Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F8322551
D8408.id30341.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
13 KB
Subscribers
None
D8408.id30341.diff
View Options
diff --git a/swh/graphql/resolvers/base_connection.py b/swh/graphql/resolvers/base_connection.py
--- a/swh/graphql/resolvers/base_connection.py
+++ b/swh/graphql/resolvers/base_connection.py
@@ -8,6 +8,8 @@
from dataclasses import dataclass
from typing import Any, List, Optional, Type, Union
+from swh.graphql.backends.archive import Archive
+from swh.graphql.backends.search import Search
from swh.graphql.errors import PaginationError
from swh.graphql.utils import utils
from swh.storage.interface import PagedResult
@@ -40,6 +42,8 @@
self.obj: Optional[Any] = obj
self.info = info
self.kwargs = kwargs
+ self.archive = Archive()
+ self.search = Search()
self._paged_data: PagedResult = paged_data
@property
diff --git a/swh/graphql/resolvers/base_node.py b/swh/graphql/resolvers/base_node.py
--- a/swh/graphql/resolvers/base_node.py
+++ b/swh/graphql/resolvers/base_node.py
@@ -6,6 +6,7 @@
from abc import ABC
from collections import namedtuple
+from swh.graphql.backends.archive import Archive
from swh.graphql.errors import ObjectNotFoundError
@@ -18,6 +19,7 @@
self.obj = obj
self.info = info
self.kwargs = kwargs
+ self.archive = Archive()
self._node = self._get_node(node_data)
# handle the errors, if any, after _node is set
self._handle_node_errors()
diff --git a/swh/graphql/resolvers/content.py b/swh/graphql/resolvers/content.py
--- a/swh/graphql/resolvers/content.py
+++ b/swh/graphql/resolvers/content.py
@@ -5,8 +5,6 @@
from typing import Union
-from swh.graphql.backends import archive
-
from .base_node import BaseSWHNode
from .directory_entry import DirectoryEntryNode
from .release import BaseReleaseNode
@@ -19,7 +17,7 @@
"""
def _get_content_by_hash(self, checksums: dict):
- content = archive.Archive().get_contents(checksums)
+ content = self.archive.get_contents(checksums)
# in case of a conflict, return the first element
return content[0] if content else None
diff --git a/swh/graphql/resolvers/directory.py b/swh/graphql/resolvers/directory.py
--- a/swh/graphql/resolvers/directory.py
+++ b/swh/graphql/resolvers/directory.py
@@ -5,7 +5,6 @@
from typing import Union
-from swh.graphql.backends import archive
from swh.model.model import Directory
from swh.model.swhids import ObjectType
@@ -40,9 +39,7 @@
# path = ""
if (
swhid.object_type == ObjectType.DIRECTORY
- and archive.Archive().is_object_available(
- swhid.object_id, swhid.object_type
- )
+ and self.archive.is_object_available(swhid.object_id, swhid.object_type)
):
# _get_directory_by_id is not making any backend call
# hence the is_directory_available validation
diff --git a/swh/graphql/resolvers/directory_entry.py b/swh/graphql/resolvers/directory_entry.py
--- a/swh/graphql/resolvers/directory_entry.py
+++ b/swh/graphql/resolvers/directory_entry.py
@@ -3,7 +3,6 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
-from swh.graphql.backends import archive
from swh.graphql.utils import utils
from swh.storage.interface import PagedResult
@@ -40,7 +39,5 @@
# FIXME, using dummy(local) pagination, move pagination to backend
# To remove localpagination, just drop the paginated call
# STORAGE-TODO
- entries = (
- archive.Archive().get_directory_entries(self.obj.swhid.object_id).results
- )
+ entries = self.archive.get_directory_entries(self.obj.swhid.object_id).results
return utils.paginated(entries, self._get_first_arg(), self._get_after_arg())
diff --git a/swh/graphql/resolvers/origin.py b/swh/graphql/resolvers/origin.py
--- a/swh/graphql/resolvers/origin.py
+++ b/swh/graphql/resolvers/origin.py
@@ -3,7 +3,6 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
-from swh.graphql.backends import archive, search
from swh.model.model import Origin
from swh.storage.interface import PagedResult
@@ -25,7 +24,7 @@
"""
def _get_node_data(self):
- return archive.Archive().get_origin(self.kwargs.get("url"))
+ return self.archive.get_origin(self.kwargs.get("url"))
class TargetOriginNode(BaseOriginNode):
@@ -52,7 +51,7 @@
def _get_paged_result(self) -> PagedResult:
# Use the search backend if a urlPattern is given
if self.kwargs.get("urlPattern"):
- origins = search.Search().get_origins(
+ origins = self.search.get_origins(
query=self.kwargs.get("urlPattern"),
after=self._get_after_arg(),
first=self._get_first_arg(),
@@ -60,6 +59,6 @@
results = [Origin(ori["url"]) for ori in origins.results]
return PagedResult(results=results, next_page_token=origins.next_page_token)
# Use the archive backend by default
- return archive.Archive().get_origins(
+ return self.archive.get_origins(
after=self._get_after_arg(), first=self._get_first_arg()
)
diff --git a/swh/graphql/resolvers/release.py b/swh/graphql/resolvers/release.py
--- a/swh/graphql/resolvers/release.py
+++ b/swh/graphql/resolvers/release.py
@@ -5,8 +5,6 @@
from typing import Union
-from swh.graphql.backends import archive
-
from .base_node import BaseSWHNode
from .snapshot_branch import BaseSnapshotBranchNode
@@ -17,7 +15,7 @@
"""
def _get_release_by_id(self, release_id):
- return (archive.Archive().get_releases([release_id]) or None)[0]
+ return (self.archive.get_releases([release_id]) or None)[0]
@property
def target_hash(self):
diff --git a/swh/graphql/resolvers/revision.py b/swh/graphql/resolvers/revision.py
--- a/swh/graphql/resolvers/revision.py
+++ b/swh/graphql/resolvers/revision.py
@@ -5,7 +5,6 @@
from typing import Union
-from swh.graphql.backends import archive
from swh.graphql.utils import utils
from swh.model.model import Revision
from swh.model.swhids import CoreSWHID, ObjectType
@@ -23,7 +22,7 @@
"""
def _get_revision_by_id(self, revision_id):
- return (archive.Archive().get_revisions([revision_id]) or None)[0]
+ return (self.archive.get_revisions([revision_id]) or None)[0]
@property
def parent_swhids(self): # for ParentRevisionConnection resolver
@@ -83,7 +82,7 @@
# FIXME, using dummy(local) pagination, move pagination to backend
# To remove localpagination, just drop the paginated call
# STORAGE-TODO (pagination)
- parents = archive.Archive().get_revisions(
+ parents = self.archive.get_revisions(
[x.object_id for x in self.obj.parent_swhids]
)
return utils.paginated(parents, self._get_first_arg(), self._get_after_arg())
@@ -99,7 +98,7 @@
_node_class = BaseRevisionNode
def _get_paged_result(self) -> PagedResult:
- log = archive.Archive().get_revision_log([self.obj.swhid.object_id])
+ log = self.archive.get_revision_log([self.obj.swhid.object_id])
# Storage is returning a list of dicts instead of model objects
# Following loop is to reverse that operation
# STORAGE-TODO; remove to_dict from storage.revision_log
diff --git a/swh/graphql/resolvers/search.py b/swh/graphql/resolvers/search.py
--- a/swh/graphql/resolvers/search.py
+++ b/swh/graphql/resolvers/search.py
@@ -3,7 +3,6 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
-from swh.graphql.backends import archive, search
from swh.storage.interface import PagedResult
from .base_connection import BaseConnection
@@ -25,7 +24,7 @@
def _get_paged_result(self) -> PagedResult:
swhid = self.kwargs.get("swhid")
results = []
- if archive.Archive().is_object_available(swhid.object_id, swhid.object_type):
+ if self.archive.is_object_available(swhid.object_id, swhid.object_type):
results = [
{
"target_hash": swhid.object_id,
@@ -40,7 +39,7 @@
_node_class = SearchResultNode
def _get_paged_result(self) -> PagedResult:
- origins = search.Search().get_origins(
+ origins = self.search.get_origins(
query=self.kwargs.get("query"),
after=self._get_after_arg(),
first=self._get_first_arg(),
diff --git a/swh/graphql/resolvers/snapshot.py b/swh/graphql/resolvers/snapshot.py
--- a/swh/graphql/resolvers/snapshot.py
+++ b/swh/graphql/resolvers/snapshot.py
@@ -5,7 +5,6 @@
from typing import Union
-from swh.graphql.backends import archive
from swh.graphql.utils import utils
from swh.model.model import Snapshot
from swh.model.swhids import ObjectType
@@ -44,9 +43,7 @@
swhid = self.kwargs.get("swhid")
if (
swhid.object_type == ObjectType.SNAPSHOT
- and archive.Archive().is_object_available(
- swhid.object_id, swhid.object_type
- )
+ and self.archive.is_object_available(swhid.object_id, swhid.object_type)
):
return self._get_snapshot_by_id(swhid.object_id)
return None
@@ -89,7 +86,7 @@
_node_class = BaseSnapshotNode
def _get_paged_result(self) -> PagedResult:
- results = archive.Archive().get_origin_snapshots(self.obj.url)
+ results = self.archive.get_origin_snapshots(self.obj.url)
snapshots = [Snapshot(id=snapshot, branches={}) for snapshot in results]
# FIXME, using dummy(local) pagination, move pagination to backend
# To remove localpagination, just drop the paginated call
diff --git a/swh/graphql/resolvers/snapshot_branch.py b/swh/graphql/resolvers/snapshot_branch.py
--- a/swh/graphql/resolvers/snapshot_branch.py
+++ b/swh/graphql/resolvers/snapshot_branch.py
@@ -5,7 +5,6 @@
from collections import namedtuple
-from swh.graphql.backends import archive
from swh.graphql.errors import ObjectNotFoundError
from swh.graphql.utils import utils
from swh.storage.interface import PagedResult
@@ -68,7 +67,7 @@
snapshot_swhid = self.snapshot_swhid()
target_branch = self.obj.target_hash
- alias_branch = archive.Archive().get_snapshot_branches(
+ alias_branch = self.archive.get_snapshot_branches(
snapshot_swhid.object_id, first=1, name_include=target_branch
)
if target_branch not in alias_branch["branches"]:
@@ -91,7 +90,7 @@
_node_class = BaseSnapshotBranchNode
def _get_paged_result(self) -> PagedResult:
- result = archive.Archive().get_snapshot_branches(
+ result = self.archive.get_snapshot_branches(
self.obj.swhid.object_id,
after=self._get_after_arg(),
first=self._get_first_arg(),
diff --git a/swh/graphql/resolvers/visit.py b/swh/graphql/resolvers/visit.py
--- a/swh/graphql/resolvers/visit.py
+++ b/swh/graphql/resolvers/visit.py
@@ -3,7 +3,6 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
-from swh.graphql.backends import archive
from swh.graphql.utils import utils
from swh.storage.interface import PagedResult
@@ -34,7 +33,7 @@
"""
def _get_node_data(self):
- return archive.Archive().get_origin_visit(
+ return self.archive.get_origin_visit(
self.kwargs.get("originUrl"), int(self.kwargs.get("visitId"))
)
@@ -48,7 +47,7 @@
def _get_node_data(self):
# self.obj.url is the origin URL
- return archive.Archive().get_origin_latest_visit(self.obj.url)
+ return self.archive.get_origin_latest_visit(self.obj.url)
class OriginVisitConnection(BaseConnection):
@@ -62,6 +61,6 @@
def _get_paged_result(self) -> PagedResult:
# self.obj.url is the origin URL
- return archive.Archive().get_origin_visits(
+ return self.archive.get_origin_visits(
self.obj.url, after=self._get_after_arg(), first=self._get_first_arg()
)
diff --git a/swh/graphql/resolvers/visit_status.py b/swh/graphql/resolvers/visit_status.py
--- a/swh/graphql/resolvers/visit_status.py
+++ b/swh/graphql/resolvers/visit_status.py
@@ -3,7 +3,6 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
-from swh.graphql.backends import archive
from swh.model.swhids import CoreSWHID, ObjectType
from swh.storage.interface import PagedResult
@@ -31,9 +30,7 @@
def _get_node_data(self):
# self.obj.origin is the origin URL
- return archive.Archive().get_latest_visit_status(
- self.obj.origin, self.obj.visitId
- )
+ return self.archive.get_latest_visit_status(self.obj.origin, self.obj.visitId)
class VisitStatusConnection(BaseConnection):
@@ -46,7 +43,7 @@
def _get_paged_result(self) -> PagedResult:
# self.obj.origin is the origin URL
- return archive.Archive().get_visit_status(
+ return self.archive.get_visit_status(
self.obj.origin,
self.obj.visitId,
after=self._get_after_arg(),
diff --git a/swh/graphql/tests/unit/backends/test_archive.py b/swh/graphql/tests/unit/backends/test_archive.py
--- a/swh/graphql/tests/unit/backends/test_archive.py
+++ b/swh/graphql/tests/unit/backends/test_archive.py
@@ -1,4 +1,4 @@
# from swh.graphql.backends import archive
# def test_get_origin():
-# assert isinstance(archive.Archive().get_origins(), object)
+# assert isinstance(self.archive.get_origins(), object)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Jun 2, 7:38 AM (5 d, 7 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3231079
Attached To
D8408: resolvers: Initialize backends in base classes for node and connection
Event Timeline
Log In to Comment