fix: address PR review feedback

1. get_all(): use LIMIT in Cypher query instead of Python slicing
2. _delete_entities/_add_entities: single commit after loop with
   rollback on failure to prevent partial commits
3. _merge_node(): combine agent_id/run_id into single SET query
   (was up to 3 round-trips, now always 1)
4. Add close() method for connection cleanup
5. Extract _get_similar_nodes() helper to deduplicate similarity logic

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
utkarsh240799
2026-03-20 19:07:32 +05:30
co-authored by Claude Opus 4.6
parent d34394ff77
commit 7193744a9d
2 changed files with 132 additions and 124 deletions
+9 -4
View File
@@ -181,13 +181,18 @@ class TestGetAll:
assert results[0]["relationship"] == "KNOWS"
assert results[0]["target"] == "bob"
def test_respects_limit(self):
def test_passes_limit_to_cypher(self):
"""Limit is enforced via LIMIT in the Cypher query, not Python slicing."""
instance = _make_instance()
instance._exec_cypher = MagicMock(return_value=[
{"source": f"n{i}", "relationship": "R", "target": f"m{i}"} for i in range(10)
{"source": "n0", "relationship": "R", "target": "m0"},
])
results = instance.get_all({"user_id": "u1"}, limit=3)
assert len(results) == 3
instance.get_all({"user_id": "u1"}, limit=3)
# Verify limit was passed as a parameter to the query
cypher_stmt = instance._exec_cypher.call_args[0][0]
assert "LIMIT %s" in cypher_stmt
params = instance._exec_cypher.call_args[1].get("params") or instance._exec_cypher.call_args[0][2]
assert 3 in params
class TestAdd: