Skip to content

refactor: extract generic fetchAllPaginated helper#39

Open
ArchiDevil wants to merge 1 commit into
mainfrom
refactor/generic-paginated-fetch
Open

refactor: extract generic fetchAllPaginated helper#39
ArchiDevil wants to merge 1 commit into
mainfrom
refactor/generic-paginated-fetch

Conversation

@ArchiDevil

Copy link
Copy Markdown
Owner

Summary

All list endpoints (, , , , , ) had the same ~40-line pagination boilerplate: get count → loop with sequential → concat → map types.

Extracted a generic fetchAllPaginated<DirectusT, ApiT> helper that:

  • Centralizes pagination logic in one place (server/utils/fetchAllPaginated.ts)
  • Uses Promise.all instead of sequential requests — pages fetch in parallel
  • Reduces each endpoint to config + mapper (~15 lines)

Changes

File Before After
spells.ts 53 lines 33 lines
feats.ts 50 lines 24 lines
backgrounds.ts 50 lines 27 lines
magic-items.ts 63 lines 34 lines
facilities.ts 52 lines 27 lines
spell-cards.ts 113 lines 93 lines
fetchAllPaginated.ts 30 lines
Total 381 268

Net -113 lines, and adding a new list endpoint is now trivial.

Bonus

Also fixes the sequential-fetch performance issue (#5 from the code review) — all pages now fetch in parallel.

All list endpoints (spells, feats, backgrounds, magic-items, facilities,
spell-cards) had the same pagination boilerplate: get count, loop with
sequential await, concat results, map types.

Replaced with a generic fetchAllPaginated<DirectusT, ApiT> helper that:
- Centralizes the pagination logic
- Uses Promise.all instead of sequential requests (parallel fetch)
- Reduces each endpoint to ~15 lines of config + mapper

Also closes #5 (sequential requests performance issue).
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