Skip to content

perf: add MongoDB indexes for high-frequency query patterns#82

Open
AdaBebe0 wants to merge 1 commit into
SwiftChainn:mainfrom
AdaBebe0:feat/db-indexes
Open

perf: add MongoDB indexes for high-frequency query patterns#82
AdaBebe0 wants to merge 1 commit into
SwiftChainn:mainfrom
AdaBebe0:feat/db-indexes

Conversation

@AdaBebe0

Copy link
Copy Markdown

Analyzes actual query usage across controllers/services and adds single-field and compound indexes on the fields those queries filter and sort by, so real read paths stop falling back to collection scans.

Delivery (src/models/Delivery.ts): status+createdAt and driver+createdAt compound indexes match delivery.service.ts#list, which optionally filters by status or driver and always sorts by createdAt desc. isDeleted+deletedAt matches delivery.service.ts#listArchived exactly.

DeliveryLegacy (src/models/deliveryModel.ts): single-field indexes on status and assignedDriver, the two fields the status-transition endpoint and any status/driver-scoped listing would filter on.

User (src/models/User.ts): compound index on role+status, the two fields checked on every authenticated request (authorize, requireRole, authenticate's suspended/banned check) and the natural filter pair for an admin user listing.

ChatMessage (src/models/ChatMessage.ts): index on createdAt, matching socketService.ts#getRecentMessages which runs on every socket connection.

LocationUpdate already had appropriate compound indexes and was left unchanged.

Closes #59

Analyzes actual query usage across controllers/services and adds
single-field and compound indexes on the fields those queries filter
and sort by, so real read paths stop falling back to collection scans.

Delivery (src/models/Delivery.ts): status+createdAt and driver+createdAt
compound indexes match delivery.service.ts#list, which optionally filters
by status or driver and always sorts by createdAt desc. isDeleted+deletedAt
matches delivery.service.ts#listArchived exactly.

DeliveryLegacy (src/models/deliveryModel.ts): single-field indexes on
status and assignedDriver, the two fields the status-transition endpoint
and any status/driver-scoped listing would filter on.

User (src/models/User.ts): compound index on role+status, the two fields
checked on every authenticated request (authorize, requireRole,
authenticate's suspended/banned check) and the natural filter pair for
an admin user listing.

ChatMessage (src/models/ChatMessage.ts): index on createdAt, matching
socketService.ts#getRecentMessages which runs on every socket connection.

LocationUpdate already had appropriate compound indexes and was left
unchanged.
@drips-wave

drips-wave Bot commented Jul 26, 2026

Copy link
Copy Markdown

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

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.

Backend: Create database indexes (MongoDB) for high-frequency queries to optimize performance

1 participant