perf: optimize Firestore reaction fetching using batched aggregation#160
Merged
Piyushydv08 merged 1 commit intoJun 2, 2026
Merged
Conversation
👷 Deploy request for safevoiceforwomen pending review.Visit the deploys page to approve it
|
Piyushydv08
approved these changes
Jun 2, 2026
Contributor
Author
|
Hello @Piyushydv08 , can you please add the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Select the type of PR (check one):
Related Issue
Link the GitHub issue this PR closes (if applicable).
Rationale / Motivation
The current story feed implementation performed Firestore reaction queries inside loops while fetching stories, creating an N+1 query pattern.
This resulted in:
This PR optimizes the reaction fetching flow by replacing per-story Firestore queries with batched queries and lightweight in-memory aggregation.
The implementation stays intentionally minimal and in-scope without introducing unnecessary abstractions or architectural changes.
Description of Changes
Frontend
Updated
src/pages/Home.tsxwhere('story_id', 'in', chunk)Updated
src/pages/Stories.tsxPerformance Optimization
Reduced Firestore query count from:
1 + N queriesto:
1 + ceil(N / 30)queriesImproved:
Code Quality
Testing Instructions
Impact Assessment
User-facing Changes
Backend/API Changes
Performance Considerations
Security Implications
Cross-browser / Device Impact
Screenshots / GIFs (if applicable)
N/A — no visual/UI changes introduced.
Checklist
Reviewer Notes
Areas to focus on:
Trade-offs:
Breaking Changes
No breaking changes introduced.
Optional Enhancements / Future Work
Possible future optimizations:
Priority / Impact Level