Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize __fetch_adb_docs #93

Merged
merged 4 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env:
jobs:
build:
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
Expand Down
19 changes: 9 additions & 10 deletions adbnx_adapter/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def arangodb_to_networkx(

# 1. Fetch ArangoDB vertices
v_col_cursor, v_col_size = self.__fetch_adb_docs(
v_col, atribs, explicit_metagraph, **adb_export_kwargs
v_col, False, atribs, explicit_metagraph, **adb_export_kwargs
)

# 2. Process ArangoDB vertices
Expand All @@ -162,12 +162,12 @@ def arangodb_to_networkx(
# Edge Collections #
####################

for e_col, atribs in metagraph["edgeCollections"].items():
for e_col, atribs in metagraph.get("edgeCollections", {}).items():
logger.debug(f"Preparing '{e_col}' edges")

# 1. Fetch ArangoDB edges
e_col_cursor, e_col_size = self.__fetch_adb_docs(
e_col, atribs, explicit_metagraph, **adb_export_kwargs
e_col, True, atribs, explicit_metagraph, **adb_export_kwargs
)

# 2. Process ArangoDB edges
Expand Down Expand Up @@ -421,6 +421,7 @@ def networkx_to_arangodb(
def __fetch_adb_docs(
self,
col: str,
is_edge: bool,
attributes: Set[str],
explicit_metagraph: bool,
**adb_export_kwargs: Any,
Expand All @@ -429,6 +430,8 @@ def __fetch_adb_docs(

:param col: The ArangoDB collection.
:type col: str
:param is_edge: True if **col** is an edge collection.
:type is_edge: bool
:param attributes: The set of document attributes.
:type attributes: Set[str]
:param explicit_metagraph: If True, only return the set of **attributes**
Expand All @@ -443,13 +446,9 @@ def __fetch_adb_docs(
"""
aql_return_value = "doc"
if explicit_metagraph:
aql_return_value = f"""
MERGE(
KEEP(doc, {list(attributes)}),
{{"_id": doc._id}},
doc._from ? {{"_from": doc._from, "_to": doc._to}}: {{}}
)
"""
default_keys = ["_id", "_key"]
default_keys += ["_from", "_to"] if is_edge else []
aql_return_value = f"KEEP(doc, {list(attributes) + default_keys})"

col_size: int = self.__db.collection(col).count()

Expand Down