Skip to content

Add database indexes to opsce entity columns for query performance#858

Merged
yusuftomilola merged 1 commit into
DistinctCodes:mainfrom
MaryammAli:Add-database-indexes-to-opsce-entity-columns-for-query-performance
Jun 1, 2026
Merged

Add database indexes to opsce entity columns for query performance#858
yusuftomilola merged 1 commit into
DistinctCodes:mainfrom
MaryammAli:Add-database-indexes-to-opsce-entity-columns-for-query-performance

Conversation

@MaryammAli
Copy link
Copy Markdown
Contributor

[BE-34] Add Database Indexes to OPSCE Entity Columns for Query Performance

Overview

This PR improves database query performance by adding indexes to frequently queried OPSCE entity columns. These indexes are designed to optimize filtering, sorting, pagination, and join operations as the dataset grows.

Problem Addressed

Several high-traffic entity fields used in WHERE, ORDER BY, and JOIN clauses currently lack database indexes. This can lead to full table scans, increased query latency, and degraded application performance as asset and audit data volumes increase.

Changes Made

Asset Entity

Added @Index() decorators to commonly queried asset fields:

  • status
  • category
  • departmentId
  • locationId
  • assignedTo
  • createdAt

The createdAt index improves:

  • Pagination performance
  • Date-range filtering
  • Sorting by creation date

AuditLog Entity

Added @Index() decorators to:

  • userId
  • resourceType
  • createdAt

These indexes optimize:

  • User activity lookups
  • Audit trail filtering
  • Time-based audit queries

MaintenanceRecord Entity

Added @Index() decorators to:

  • assetId
  • scheduledDate

These indexes improve:

  • Asset maintenance history lookups
  • Scheduled maintenance queries
  • Date-based maintenance reporting

Database Migration

  • Generated a new TypeORM migration to create all required indexes.
  • Reviewed existing schema definitions to avoid creating duplicate indexes.
  • Excluded indexes that are already automatically created by TypeORM for foreign key constraints where applicable.

Performance Benefits

  • Faster asset filtering by status, category, department, location, and assignee.
  • Improved pagination and sorting performance for large datasets.
  • More efficient audit log searches and reporting.
  • Faster maintenance scheduling and asset maintenance lookups.
  • Reduced database load from full table scans.

Acceptance Criteria

  • Asset.status, Asset.category, Asset.departmentId, Asset.locationId, and Asset.assignedTo have indexes.
  • Asset.createdAt is indexed for pagination and date-range queries.
  • AuditLog.userId, AuditLog.resourceType, and AuditLog.createdAt have indexes.
  • MaintenanceRecord.assetId and MaintenanceRecord.scheduledDate have indexes.
  • A TypeORM migration is included to create the indexes.
  • No unnecessary or duplicate indexes are introduced.

Notes

Add database indexes to opsce entity columns for query performance
@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

@MaryammAli is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 31, 2026

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

Copy link
Copy Markdown
Collaborator

@yusuftomilola yusuftomilola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your contribution

@yusuftomilola yusuftomilola merged commit eaa5696 into DistinctCodes:main Jun 1, 2026
1 of 8 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.

[BE-34] Add database indexes to opsce entity columns for query performance

2 participants