Skip to content

Conversation

@alexjaniak
Copy link
Collaborator

Problem

The /dao/proposals/all endpoint was extremely slow (5-15+ seconds) because it made sequential RPC and IPFS calls:

  • N sequential moderator fetches (one per DAO)
  • N×M sequential proposal fetches (one per proposal per DAO)
  • N×M sequential IPFS metadata fetches

Solution

Restructured to fetch everything in parallel:

  1. Pre-build parent DAO map - Eliminates N+1 DB queries for child DAOs
  2. Parallel moderator fetches - All moderators fetched via Promise.all
  3. Parallel proposal fetches - All proposals fetched via Promise.all
  4. Parallel IPFS with deduplication - Collect unique CIDs, fetch once, build lookup map

Expected Improvement

Metric Before After
Response time 5-15s ~1-2s
RPC calls Sequential N + N×M Parallel batches
IPFS calls N×M (with duplicates) Unique CIDs only

Notes

  • No functional changes to response format
  • Concurrency is controlled by Promise.all (could add p-limit if needed)
  • IPFS metadata is deduplicated before fetching

Key optimizations:
- Pre-build parent DAO map to avoid N+1 DB queries
- Parallel fetch all moderators (was sequential per-DAO)
- Parallel fetch all proposals (was sequential per-proposal)
- Parallel fetch all IPFS metadata with deduplication
- Single pass metadata map lookup instead of per-proposal fetch

Expected improvement: 5-15s → ~1-2s for typical loads
- Restore getDaoStatsBatch for /dao route (1 query vs N)
- Restore PENDING moderator check in /dao/:daoPda/proposals
- Remove unused parallelLimit helper function
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