Skip to content

fix: replace N+1 loop in QueryService.findRelatedEndpoints() with batch Cypher query#12

Merged
aksOps merged 1 commit into
mainfrom
fix/query-service-related-endpoints-n-plus-one
Apr 3, 2026
Merged

fix: replace N+1 loop in QueryService.findRelatedEndpoints() with batch Cypher query#12
aksOps merged 1 commit into
mainfrom
fix/query-service-related-endpoints-n-plus-one

Conversation

@aksOps

@aksOps aksOps commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • findRelatedEndpoints() was executing up to 50 separate findNeighbors() Cypher queries in a loop (one per search result)
  • Added GraphStore.findEndpointNeighborsBatch(List<String> nodeIds) that fetches all endpoint/websocket endpoint neighbors in a single MATCH ... WHERE n.id IN $nodeIds AND m.kind IN [...] query
  • QueryService.findRelatedEndpoints() now separates the direct-endpoint check from the neighbor traversal and uses the batch method for the latter
  • connected_via field and deduplication semantics are fully preserved

Test plan

  • 3 new unit tests in QueryServiceTest: batch query usage (verifies findNeighbors is never called), direct endpoint matches, deduplication
  • All 1459 tests pass, 0 failures
  • Relates to RAN-59

🤖 Generated with Claude Code

…her query

Added GraphStore.findEndpointNeighborsBatch() that fetches all endpoint
neighbors for a list of node IDs in one MATCH ... WHERE n.id IN $nodeIds
query, eliminating up to 50 separate findNeighbors() calls per invocation.

QueryService.findRelatedEndpoints() now separates the direct-endpoint pass
from the neighbor pass, using the new batch method for the latter. Deduplication
and connected_via semantics are preserved.

Added 3 unit tests covering: batch usage (verifying findNeighbors is never
called), direct endpoint matches, and deduplication.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@sonarqubecloud

sonarqubecloud Bot commented Apr 1, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
42.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@aksOps aksOps merged commit f8148bb into main Apr 3, 2026
9 of 10 checks passed
aksOps added a commit that referenced this pull request Apr 3, 2026
Resolves conflicts between backend chain (PRs #12-#16) and detection quality fixes:
- TopicLinker: preserved extended SENDS_TO/RECEIVES_FROM/PUBLISHES/LISTENS support from both chains
- GraphStore/EnrichCommand: kept search_index (fulltext, keyword analyzer, label_lower/fqn_lower) from backend chain
- QueryService: preserved batch endpoint neighbor query from backend chain + stats improvements
- NestJSControllerDetectorTest/NestJSGuardsDetectorTest: merged no-match discriminator tests

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@aksOps aksOps deleted the fix/query-service-related-endpoints-n-plus-one branch April 3, 2026 15:58
aksOps added a commit that referenced this pull request Apr 3, 2026
… fix)

The merge of feat/phase5-dashboard-redesign into main introduced a duplicate
definition of findEndpointNeighborsBatch(List<String>). Both versions had
identical semantics but different implementation style:

Kept: the first (from the backend chain PRs #12-16) which uses
NodeKind.ENDPOINT.getValue() for type safety and UNWIND/MATCH pattern
with $ids parameter.

Removed: the second (from phase5) which used string literals
('ENDPOINT', 'WEBSOCKET_ENDPOINT') and IN $nodeIds pattern.

Fixes: compilation failure on main (javac error: method already defined).

Co-Authored-By: Paperclip <noreply@paperclip.ing>
aksOps added a commit that referenced this pull request Apr 3, 2026
Two duplicate method definitions were introduced when feat/phase5-dashboard-redesign
was merged into main, because both the backend chain (PRs #12-16) and the phase5
branch independently added the same methods:

1. GraphStore.findEndpointNeighborsBatch(List<String>):
   - Kept: UNWIND/$ids/NodeKind.getValue() version (from backend chain, type-safe)
   - Removed: IN $nodeIds/string literal version (from phase5)

2. TopicLinkerTest.determinismTest():
   - Kept: multi-producer/multi-consumer test with PRODUCES+CONSUMES+PUBLISHES+LISTENS
     and TOPIC+EVENT nodes (more comprehensive, verifies target ID equality)
   - Removed: simpler 3-edge test (from backported detection-quality-fixes commit)

Fixes: javac compilation failures on main branch.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant