Add `take` limits and indexes to the 20+ unbounded `.find()` repository calls
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Refactor
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- nodejs, typescript
- Domain
- database
Research direction
Start with the listed .find() sites, beginning with the single-row lookups in src/core/auth/wallet-auth.service.ts and src/blockchain/oracle/services/price-feed.service.ts, and decide per site between findOne, a bounded page, or leaving it alone. Leave user.service.ts:45 as a deliberate batch loader and add a comment saying so. Index changes belong in migrations, with src/common/database/database-index.service.ts used only as a suggestion source. Done means every site is reviewed and recorded, retained filters have migrations, and before/after timings are attached.
Written by the indexing model from the issue text.
Description
Problem
A scan of src/ found more than 20 repository .find({...}) calls with no take/limit, so they load the entire matching table. Confirmed sites:
src/blockchain/oracle/services/nonce-management.service.ts:182src/blockchain/oracle/services/oracle.service.ts:228, 241, 348src/blockchain/oracle/services/price-feed.service.ts:184src/blockchain/oracle/services/submission-batch.service.ts:113, 329, 359, 460src/core/auth/delegation.service.ts:305, 353, 431src/core/auth/enhanced-auth.service.ts:494src/core/auth/wallet-auth.service.ts:290, 391, 472src/core/auth/grantfox-oauth.service.ts:410, 480src/core/auth/oauth.strategy.ts:268src/core/user/user.service.ts:45
Not every one is a defect — user.service.ts:45 uses In(uniqueIds) with a caller-supplied id list and is a deliberate batch loader. But several of the others look like lookups that should return one row, and the oracle and delegation ones operate on tables that grow with activity.
Why it matters
Unbounded reads have cost proportional to table size, forever. They are also a straightforward resource-exhaustion lever: any code path that reaches one of these with a permissive filter reads everything. On the oracle and submission tables this becomes an operational problem as volume grows, because these are the hottest write paths in the system.
Suggested Direction
- Triage each call rather than blanket-limiting. For each site, decide whether it wants one row (
findOne), a bounded page, or genuinely everything.- Sites that look up a single nonce, price, or delegation by a unique key should almost certainly be
findOne— that is both faster and clearer about intent. - Sites that genuinely need many rows should get an explicit, documented limit and a paginated interface.
- Sites that look up a single nonce, price, or delegation by a unique key should almost certainly be
- Do not cap code that is correct without a cap. A batch loader keyed on a bounded id list (as in
user.service.ts:45) should stay as-is; note why in a comment so a future reader does not "fix" it. - Add supporting indexes for any filter you keep, via migrations.
src/common/database/database-index.service.tscan generate recommendations, and there isnpm run migration:generate— but review anything it suggests rather than applying it wholesale. Note that service buildsCREATE INDEXfrom a template string (database-index.service.ts:114-116); do not follow that pattern. - Add a lint or review heuristic to catch new unbounded reads. An ESLint rule is hard here; a documented convention plus review is more realistic.
Constraints
- Changing an unbounded read to a paginated one changes API behaviour if it is behind an endpoint. Those need a breaking-change note in
CHANGELOG.mdand maintainer sign-off. - Internal-only reads can be changed freely.
- Indexes change the schema — use migrations, never
synchronize. - Benchmark before and after on realistic data volumes; an index that is never used by the query planner costs write throughput for nothing.
Acceptance Criteria
- Every
.find()insrc/either has an explicit bound or a comment justifying its absence. - Single-row lookups use
findOne. - Indexes for retained filters are added via migrations.
- Behaviour changes on public endpoints are documented and approved.
- The full list of reviewed sites is recorded in the issue.
- A before/after query-count or timing measurement is included.
- Dominant language
- TypeScript
- Stars
- 7
- Forks
- 55
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 5
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SourceXXL/alian_structure-api
-
good first issue help wanted security
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SourceXXL/alian_structure-api#266 ·
-
Parallelize the cache-warming loop in `cache-warming.service.ts` — warmers run strictly sequentiallyPossibly taken @syntaxsuuvam-spec claimed this 2 days ago. Opengood first issue performance
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SourceXXL/alian_structure-api#240 ·
-
documentation help wanted intermediate refactor
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
SourceXXL/alian_structure-api#215 ·
-
good first issue refactor tooling
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
SourceXXL/alian_structure-api#199 ·
-
help wanted intermediate refactor
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
SourceXXL/alian_structure-api#196 ·
All issues in SourceXXL/alian_structure-api
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 70/100
siyuan-note/siyuan#20517 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
NaturalIntelligence/fast-xml-parser#890 · 1 comment ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
zsviczian/obsidian-excalidraw-plugin#3000 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
pnpm/get.pnpm.io#68 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
nuxt-modules/better-auth#578 · 2 comments ·
Maintainers usually reply within 1 day