perf: add MongoDB indexes for high-frequency query patterns#82
Open
AdaBebe0 wants to merge 1 commit into
Open
Conversation
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.
|
@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! 🚀 |
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.
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