bitflicker64 commented on code in PR #432:
URL: https://github.com/apache/hugegraph-ai/pull/432#discussion_r4556780979


##########
ontogeny/tests/test_engine_functions.py:
##########
@@ -234,6 +234,86 @@ async def test_traverse_three_hops(self, env):
         assert [s_["type"] for s_ in out["steps"]] == ["material", "bom", 
"product"]
         assert out["final_ids"] == ["P-200"]
 
+    async def test_traverse_batches_fk_reads_per_hop(self, env, monkeypatch):
+        q, repo = env["query"], env["repo"]
+        batched: list[bool] = []
+        single: list[str] = []
+        orig_batch = repo.link_members_by_ids
+        orig_single = q._linked_ids
+
+        async def counting_batch(session, link_name, ids, *, from_source, 
**kw):
+            batched.append(from_source)
+            return await orig_batch(session, link_name, ids, 
from_source=from_source, **kw)
+
+        async def counting_single(session, link_name, obj_id, *, from_source):
+            single.append(obj_id)
+            return await orig_single(session, link_name, obj_id, 
from_source=from_source)
+
+        monkeypatch.setattr(repo, "link_members_by_ids", counting_batch)
+        monkeypatch.setattr(q, "_linked_ids", counting_single)
+
+        async with env["maker"]() as s:
+            out = await q.traverse(
+                s,
+                "equipment",

Review Comment:
   Important: the `product-manufacturing` package has no `equipment` object or 
`step-equipment` link, so this test fails with `NotFoundError: unknown object 
type 'equipment'`. Traverse `work-center` over `operation-work-center` (for 
example `WC-01`, `WC-02`) and assert on the operation ids that fixture holds.



##########
ontogeny/tests/test_engine_functions.py:
##########
@@ -234,6 +234,86 @@ async def test_traverse_three_hops(self, env):
         assert [s_["type"] for s_ in out["steps"]] == ["material", "bom", 
"product"]
         assert out["final_ids"] == ["P-200"]
 
+    async def test_traverse_batches_fk_reads_per_hop(self, env, monkeypatch):
+        q, repo = env["query"], env["repo"]
+        batched: list[bool] = []
+        single: list[str] = []
+        orig_batch = repo.link_members_by_ids
+        orig_single = q._linked_ids
+
+        async def counting_batch(session, link_name, ids, *, from_source, 
**kw):
+            batched.append(from_source)
+            return await orig_batch(session, link_name, ids, 
from_source=from_source, **kw)
+
+        async def counting_single(session, link_name, obj_id, *, from_source):
+            single.append(obj_id)
+            return await orig_single(session, link_name, obj_id, 
from_source=from_source)
+
+        monkeypatch.setattr(repo, "link_members_by_ids", counting_batch)
+        monkeypatch.setattr(q, "_linked_ids", counting_single)
+
+        async with env["maker"]() as s:
+            out = await q.traverse(
+                s,
+                "equipment",
+                ["EQ-02", "EQ-07"],
+                SUPER,
+                [
+                    {"link": "step-equipment", "direction": "out"},
+                    {"link": "step-equipment", "direction": "in"},
+                ],
+            )
+        # one batched read per hop (source side, then target side), never per 
id
+        assert single == []
+        assert batched == [True, False]
+        assert sorted(out["steps"][1]["ids"]) == ["PS-7111", "PS-7112", 
"PS-7121", "PS-7131", "PS-7132"]
+        assert sorted(out["final_ids"]) == ["EQ-02", "EQ-07"]
+        pairs = {(e["source"]["id"], e["target"]["id"]) for e in out["edges"]}
+        assert ("EQ-02", "PS-7111") in pairs
+        assert ("EQ-07", "PS-7132") in pairs
+        assert ("EQ-02", "PS-7112") not in pairs
+
+    async def test_traverse_batches_join_table_reads_per_hop(self, join_env, 
monkeypatch):
+        import datetime as dt
+
+        q, repo = join_env["query"], join_env["repo"]
+        calls: list[tuple[str, list[str], bool]] = []
+        orig_batch = repo.link_members_by_ids
+
+        async def counting_batch(session, link_name, ids, *, from_source, 
**kw):
+            calls.append((link_name, list(ids), from_source))
+            return await orig_batch(session, link_name, ids, 
from_source=from_source, **kw)
+
+        monkeypatch.setattr(repo, "link_members_by_ids", counting_batch)
+
+        now = dt.datetime.now(dt.UTC)

Review Comment:
   Important: `datetime.UTC` exists only from Python 3.11, and `pyproject.toml` 
declares `>=3.10` with CI on 3.10, so this line raises `AttributeError`. Use 
`dt.timezone.utc`, as the test at line 204 does.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to