n-plus-one-loop-call-miner
Read-only Insights package for detecting likely N+1 queries and external/service calls that happen inside loops.
What It Does
- Scans
js,jsx,ts,tsx,mjs,cjs,mts, andctsfiles. - Detects risky call sites inside statement loops and callback-based iteration.
- Emits metrics only. It does not rewrite source files.
Detection Scope
Loop shapes:
for,for...of,for...in,while,do...whilemap,forEach,filter,reduce,some,every,flatMapPromise.all(items.map(...))Promise.allSettled(items.map(...))
Risky call kinds:
- Query-style calls such as
findMany,query,execute,selectFrom - Repository/data-access calls on
repository,repo,dao,store - Network calls such as
fetch,axios.*,request.* - Service/client calls on names containing
Client,Service,Api,Reader,Catalog,Discovery - Cloud/client SDK calls such as
eksClient.describeCluster(...) - Lower-confidence generic async calls when they are awaited inside loops or run inside async iteration callbacks
Workflow
Workflow step name:
Scan JS/TS for N+1 and loop calls (read-only)
This package has no workflow parameters and no AI cleanup step because the spec requires a read-only analysis workflow.
Metric
Metric emitted:
loop-call-risk
Metric cardinalities:
riskKind:n_plus_one_query,external_call_in_loop,service_call_in_loop,parallelized_loop_callseverity:high,medium,lowloopKind:for,for_of,for_in,while,do_while,map,forEach,filter,reduce,some,every,flatMap,promise_all_map,promise_allsettled_mapexecutionStyle:serial,parallel,callback,unknowncallKind:query,network,service,client_sdk,repository,generic_async_callcallee: normalized callee text such ascatalogClient.addLocation,eksClient.describeCluster,fetch,repository.findByPkcallFamily: stable bucket such ascatalog,discovery,reader,aws_sdk,gcp_sdk,repository,orm,http,generic_client,generic_async
Insights Query Example
ts
File-count query example:
ts
Development
bash
The JSSG fixture harness verifies the read-only behavior and example coverage. The standard fixture harness does not expose metric assertions directly, so metric validation is covered here by package validation plus the codemod implementation using useMetricAtom("loop-call-risk") with the documented cardinalities.
License
MIT