Skip to content

Feat/1222 add experiment metric indexes - #1367

Open
Peolite001 wants to merge 3 commits into
rinafcode:mainfrom
Peolite001:feat/1222-add-experiment-metric-indexes
Open

Feat/1222 add experiment metric indexes#1367
Peolite001 wants to merge 3 commits into
rinafcode:mainfrom
Peolite001:feat/1222-add-experiment-metric-indexes

Conversation

@Peolite001

Copy link
Copy Markdown

Summary

Closes #1222

Adds database indexes to the experiment_metrics table to prevent sequential scans as the table grows. Both entity-level @Index decorators and a corresponding migration are included so existing databases are updated via a reviewable migration.

Changes

src/ab-testing/entities/experiment-metric.entity.ts

  • Imported Index from typeorm
  • Added four @Index decorators to the entity class:
Index Column(s) Rationale
IDX_experiment_metrics_experiment_id experimentId Foreign key used in every JOIN when loading the experiment.metrics relation
IDX_experiment_metrics_type type Filtering/grouping metrics by metric type
IDX_experiment_metrics_created_at createdAt ORDER BY createdAt DESC in list queries
IDX_experiment_metrics_experiment_is_primary experimentId, isPrimary Composite index for "get primary metric(s) for a given experiment"

src/migrations/1801000000000-add-experiment-metric-indexes.ts (new)

  • Creates the same four indexes using queryRunner.createIndices
  • down() drops them in reverse order for clean rollback

Checklist

  • Entity carries indexes covering common lookup/foreign-key columns
  • Migration creates the indexes and runs cleanly on an existing database
  • No duplicate/redundant indexes introduced
  • down() migration cleanly rolls back all indexes

- Add @Index decorators for experimentId FK, type, createdAt, and
  composite (experimentId, isPrimary) to ExperimentMetric entity
- Add migration 1801000000000 to create the same indexes on existing
  databases with a clean down() rollback
@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

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

@Peolite001

Copy link
Copy Markdown
Author

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

done

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Your workflow is still failing.
Run npm run lint to view the errors and fix it

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 experiment-metric entity

2 participants