Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123344
D8580.id30953.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D8580.id30953.diff
View Options
diff --git a/java/src/main/java/org/softwareheritage/graph/rpc/Traversal.java b/java/src/main/java/org/softwareheritage/graph/rpc/Traversal.java
--- a/java/src/main/java/org/softwareheritage/graph/rpc/Traversal.java
+++ b/java/src/main/java/org/softwareheritage/graph/rpc/Traversal.java
@@ -292,13 +292,13 @@
if (nodeMatchesConstraints) {
if (nodeBuilder != null) {
nodeObserver.onNext(nodeBuilder.build());
- }
- if (remainingMatches >= 0) {
- remainingMatches--;
- if (remainingMatches == 0) {
- // We matched as many nodes as allowed
- throw new StopTraversalException();
+ if (remainingMatches >= 0) {
+ remainingMatches--;
+ if (remainingMatches == 0) {
+ // We matched as many nodes as allowed
+ throw new StopTraversalException();
+ }
}
}
}
diff --git a/swh/graph/tests/test_http_client.py b/swh/graph/tests/test_http_client.py
--- a/swh/graph/tests/test_http_client.py
+++ b/swh/graph/tests/test_http_client.py
@@ -127,6 +127,27 @@
assert set(actual) == set(expected)
+@pytest.mark.parametrize("max_matching_nodes", [0, 1, 2, 3, 4, 5, 10, 1 << 31])
+def test_visit_nodes_filtered_limit(graph_client, max_matching_nodes):
+ actual = list(
+ graph_client.visit_nodes(
+ "swh:1:rel:0000000000000000000000000000000000000010",
+ return_types="dir",
+ max_matching_nodes=max_matching_nodes,
+ )
+ )
+ expected = [
+ "swh:1:dir:0000000000000000000000000000000000000002",
+ "swh:1:dir:0000000000000000000000000000000000000008",
+ "swh:1:dir:0000000000000000000000000000000000000006",
+ ]
+ if max_matching_nodes == 0:
+ assert set(actual) == set(expected)
+ else:
+ assert set(actual) <= set(expected)
+ assert len(actual) == min(3, max_matching_nodes)
+
+
def test_visit_nodes_filtered_star(graph_client):
actual = list(
graph_client.visit_nodes(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 1:16 AM (20 h, 12 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3217976
Attached To
D8580: Apply 'max_matching_nodes' restriction after 'return_types' filter
Event Timeline
Log In to Comment