feat(moderation): add database indexes to ReviewItem entity - #1411
Merged
RUKAYAT-CODER merged 2 commits intoSep 2, 2026
Conversation
Add @Index decorators and a migration for commonly queried columns on the ReviewItem entity to avoid sequential scans as the table grows. ## Indexes added 1. `IDX_review_items_status` on `status` — covers the `WHERE status = 'pending'` filter used by `ManualReviewService.getQueue()`. 2. `IDX_review_items_safetyScore_createdAt` composite on `(safetyScore, createdAt)` — covers the `ORDER BY safetyScore DESC, createdAt ASC` sort used by `getQueue()` to prioritise high-risk items, then oldest-first. 3. `IDX_review_items_sourceType` on `sourceType` — supports lookups by source type for content-report linkage. 4. `IDX_review_items_sourceId` on `sourceId` — supports joins / filters by source identifier. 5. `IDX_review_items_reportId` on `reportId` — supports joins / filters by report identifier. ## Migration New migration `1807000000000-add-review-item-indexes.ts` creates the indexes with `CREATE INDEX IF NOT EXISTS` and drops them in reverse order in `down()`. The migration uses only the passed QueryRunner (no separate connections) and passes the `validate-migrations.js` CI check. Closes rinafcode#1243 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@aigbagbobila 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! 🚀 |
Contributor
|
Well done on the job done so far! |
The added Index import pushed the single-line import past the 100-char print width, failing the prettier lint check in CI. Expand it to one specifier per line. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
Contributor
Author
|
Kindly review and merge |
Contributor
|
Thank you for contributing to the project. |
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.
Closes #1243
Add @Index decorators and a migration for commonly queried columns on the ReviewItem entity to avoid sequential scans as the table grows.
Indexes added
IDX_review_items_statusonstatus— covers theWHERE status = 'pending'filter used byManualReviewService.getQueue().IDX_review_items_safetyScore_createdAtcomposite on(safetyScore, createdAt)— covers theORDER BY safetyScore DESC, createdAt ASCsort used bygetQueue()to prioritise high-risk items, then oldest-first.IDX_review_items_sourceTypeonsourceType— supports lookups by source type for content-report linkage.IDX_review_items_sourceIdonsourceId— supports joins / filters by source identifier.IDX_review_items_reportIdonreportId— supports joins / filters by report identifier.Migration
New migration
1807000000000-add-review-item-indexes.tscreates the indexes withCREATE INDEX IF NOT EXISTSand drops them in reverse order indown(). The migration uses only the passed QueryRunner (no separate connections) and passes thevalidate-migrations.jsCI check.Closes #1243
🤖 Generated with Codebuff