Skip to content

Add quest analytics rollup job - #604

Open
Nemenwq wants to merge 1 commit into
MindBlockLabs:mainfrom
Nemenwq:nightl-quest
Open

Add quest analytics rollup job#604
Nemenwq wants to merge 1 commit into
MindBlockLabs:mainfrom
Nemenwq:nightl-quest

Conversation

@Nemenwq

@Nemenwq Nemenwq commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

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

- 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
@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
mind-block-app-frontend Skipped Skipped Jul 27, 2026 9:48pm

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.

Implement nightly quest analytics rollup job

1 participant