Skip to content

feat(moderation): add database indexes to ReviewItem entity - #1411

Merged
RUKAYAT-CODER merged 2 commits into
rinafcode:mainfrom
aigbagbobila:feat/add-review-item-indexes
Sep 2, 2026
Merged

feat(moderation): add database indexes to ReviewItem entity#1411
RUKAYAT-CODER merged 2 commits into
rinafcode:mainfrom
aigbagbobila:feat/add-review-item-indexes

Conversation

@aigbagbobila

Copy link
Copy Markdown
Contributor

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

  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 #1243

🤖 Generated with Codebuff

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>
@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@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! 🚀

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.

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

Copy link
Copy Markdown
Contributor Author

Kindly review and merge

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER
RUKAYAT-CODER merged commit 159d0c3 into rinafcode:main Sep 2, 2026
3 checks passed
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 database indexes to the review-item entity

3 participants