Batch operation refactoring#297
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #297 +/- ##
==========================================
- Coverage 87.81% 86.64% -1.18%
==========================================
Files 57 57
Lines 4998 5181 +183
Branches 877 924 +47
==========================================
+ Hits 4389 4489 +100
- Misses 384 444 +60
- Partials 225 248 +23 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
||
| def reduce_node_added_events( | ||
| event_args: Iterable[tuple[int, dict[str, Any]]], | ||
| ) -> tuple[int | list[int], dict[str, Any] | list[dict[str, Any]]]: |
There was a problem hiding this comment.
@yfukai, could you add the documentation to the public functions of this file?
| for i in range(0, len(edge_ids), chunk_size): | ||
| chunk = edge_ids[i : i + chunk_size] | ||
| existing.update( | ||
| row[0] for row in session.query(self.Edge.edge_id).filter(self.Edge.edge_id.in_(chunk)).all() |
There was a problem hiding this comment.
@yfukai, is there a way to query the missing edge IDs during the delete query? And if some are missing, it discards the session rather than committing and raises the error.
The goal is to reduce the number of queries.
There was a problem hiding this comment.
I cleaned up the code!
| for nid in node_ids: | ||
| self.node_removed.emit(nid, old_attrs_per_node[nid]) |
There was a problem hiding this comment.
Would it make sense to have a emit_node_deleted_events?
|
I worked on the followings:
|
|
|
||
| def reduce_node_added_events( | ||
| event_args: Iterable[tuple[int, dict[str, Any]]], | ||
| ) -> tuple[int | list[int], dict[str, Any] | list[dict[str, Any]]]: |
| for nid in node_ids: | ||
| self.node_removed.emit(nid, old_attrs_per_node[nid]) |
| for i in range(0, len(edge_ids), chunk_size): | ||
| chunk = edge_ids[i : i + chunk_size] | ||
| existing.update( | ||
| row[0] for row in session.query(self.Edge.edge_id).filter(self.Edge.edge_id.in_(chunk)).all() |
There was a problem hiding this comment.
I cleaned up the code!
|
Thanks @yfukai |
Human summary
batch_remove_*bulk_add_...insideadd_...Copilot Summary
This pull request introduces bulk mutation operations and refactors node and edge addition/removal logic across the graph array and graph view classes. The changes improve efficiency, ensure atomic validation, and unify signal emission for both single and bulk operations. The most important updates are summarized below.
Bulk mutation API additions
bulk_remove_nodesandbulk_remove_edgesmethods toBaseGraph,RustWorkXGraph, andGraphView, enabling efficient removal of multiple nodes or edges at once with atomic validation and proper signal emission. [1] [2] [3] [4] [5]_bulk_add_nodes_local,_bulk_remove_nodes_local,_bulk_add_edges_local,_bulk_remove_edges_local) inRustWorkXGraphto centralize and optimize node/edge manipulation logic.Signal emission and event handling improvements
emit_node_added_events,emit_node_updated_events), ensuring consistent and efficient signal handling for both single and bulk operations. [1] [2] [3] [4] [5]GraphArrayevent handlers to support bulk node add/update events by iterating over event sequences, improving compatibility with the new bulk APIs. [1] [2]Codebase and API consistency