feat: optimize analytics via MongoDB aggregations and Redis caching#1306
Open
PremSahith wants to merge 1 commit into
Open
feat: optimize analytics via MongoDB aggregations and Redis caching#1306PremSahith wants to merge 1 commit into
PremSahith wants to merge 1 commit into
Conversation
|
@PremSahith is attempting to deploy a commit to the jiya's projects Team on Vercel. A member of the Team first needs to authorize it. |
✅ Deploy Preview for codevibeforyou canceled.
|
Contributor
Author
|
@JiyaBatra please review and merge this |
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.
🛠️ Related Issue
Closes: #1297
📌 Description
This PR significantly optimizes the application's heavy data-processing endpoints by offloading complex operations from the Node.js event loop to MongoDB's Aggregation Engine. It also introduces a Redis caching layer for the most expensive, high-traffic endpoints (leaderboards) to prevent database strain and minimize latency at scale.
✨ Changes Made
Progress,Analytics, andExamResultmodels to allow MongoDB to efficiently$matchand$sortdata before aggregating it.progressController.jsto use a$facetaggregation, allowing the system to compute the paginated leaderboard and total counts in a single DB query. Integrated a 10-minute Redis caching layer.examController.js'sgetMyResultsto compute user attempts, best scores, and pass counts entirely in the database. Added a new/api/exam/leaderboardroute with Redis caching to compute top scores globally or per-course.analyticsController.js(includingbuildWeeklyStats) with a powerful MongoDB$facetaggregation that computes weekly buckets, point totals, and event filtering natively in the DB layer.📷 Screenshots
N/A - This is a purely backend performance and architectural optimization.
🧪 Type of Change
✔️ Checklist
🚨 Notes for Contributors
6379, or configure the connection string viaREDIS_URLin the.envfile. (The application will gracefully fallback to direct database queries if Redis is unavailable).