Skip to content

Fix/issue 1022 - #1108

Open
laxjovial wants to merge 3 commits into
rinafcode:mainfrom
laxjovial:fix/issue-1022
Open

Fix/issue 1022#1108
laxjovial wants to merge 3 commits into
rinafcode:mainfrom
laxjovial:fix/issue-1022

Conversation

@laxjovial

Copy link
Copy Markdown
Contributor

📝 Description

This pull request resolves Issue #1022 by adding critical database indexes to the gamification entities. Previously, heavy read operations like leaderboard aggregations and per-user ledger history scans resulted in full table scans on point_transactions, which is the highest-write and highest-scan table in the module.

🛠️ Changes Made

  • PointTransaction Entity: Added @Index(['user', 'createdAt']) to optimize per-user time window queries, and @Index(['activityType']) to speed up categorical metric scans.
  • UserChallenge Entity: Added @Index(['userId', 'challengeId']) to optimize user participation checks.
  • Challenge Entity: Added @Index(['type']) to accelerate lookup queries mapping specific challenge types.
  • TierReward Entity: Explicitly indexed the tier enumeration (@Index(['tier'])) to ensure fast promotion checks.
  • Migration: Generated 1750000000000-add-gamification-indexes.ts with CREATE INDEX IF NOT EXISTS commands to safely apply these changes to the schema.

🧪 Acceptance Criteria Addressed

  • Per-user point history queries now use an index (IDX_point_transactions_user_createdAt).
  • Leaderboard aggregation no longer performs a full sequential scan.
  • A migration is provided reflecting the entity index changes.

🔗 Related Issues

@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@laxjovial Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Well done on the job done so far!
Kindly fix workflow to pass

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.

Add missing database indexes to gamification entities

2 participants