Add quest analytics rollup job - #604
Open
Nemenwq wants to merge 1 commit into
Open
Conversation
- Create QuestAnalytics entity for daily quest aggregation - Add QuestAnalyticsRollupJob scheduled at 00:30 UTC - Aggregate daily quest assignment/completion counts - Create migration for quest_analytics table - Register job and entities in analytics module
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
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.
Add a Cron job to aggregate daily quest assignment/completion counts into QuestAnalytics rows.
Problem
The get-quest-completion-rate.provider.ts currently needs to join raw quest and event tables on every request to calculate completion rates, which is inefficient.
Solution
Created a nightly rollup job that materializes pre-aggregated quest analytics data, enabling efficient reads without joining raw tables.
Changes
Files Created:
backend/src/analytics/entities/quest-analytics.entity.ts - Entity with daily quest statistics (date, assignedCount, completedCount)
backend/src/analytics/jobs/quest-analytics-rollup.job.ts - Cron job that aggregates DailyQuest data for the previous day
backend/src/database/migrations/20260727000000-AddQuestAnalyticsTable.ts - Migration for quest_analytics table
Files Modified:
backend/src/analytics/analytics.module.ts - Registered QuestAnalytics, DailyQuest entities and QuestAnalyticsRollupJob
Key Features
Cron Schedule: 30 0 * * * (00:30 UTC daily) - runs after quest reset time
Aggregation Logic: Counts quests by questDate and isCompleted status
Idempotent: Safe to re-run (replaces existing data for the same date)
Logging: Logs assignment and completion counts for each rollup
Implementation Details
The job follows the same pattern as DailyActiveUsersRollupJob and produces one row per day with:
Total quests assigned for that date
Total quests completed for that date
This enables get-quest-completion-rate.provider.ts to read pre-aggregated data instead of joining raw quest tables on every request.
closes #549