Skip to content

**Title:** perf: optimize database operations and backend performance#673

Open
saidai-bhuvanesh wants to merge 4 commits into
adithyan-css:mainfrom
saidai-bhuvanesh:feature/database-perf-audit
Open

**Title:** perf: optimize database operations and backend performance#673
saidai-bhuvanesh wants to merge 4 commits into
adithyan-css:mainfrom
saidai-bhuvanesh:feature/database-perf-audit

Conversation

@saidai-bhuvanesh
Copy link
Copy Markdown

@saidai-bhuvanesh saidai-bhuvanesh commented Jun 5, 2026

Summary:
This PR addresses performance bottlenecks caused by missing database indexes and redundant query calls across the admin dashboard and checkout flow.

Changes:

  • models/Order.js — Added 5 indexes: created_at sort index, compound phone+total+created_at for duplicate detection, status, payment_status, and phone for admin filters
  • models/Otp.js — Added compound phone+created_at index for fast OTP lookups
  • models/Product.js — Added compound type+id_ref index for instant per-item price resolution during checkout
  • api/controllers/orderController.js — Refactored getStats() from 4 separate DB queries to a single $facet aggregation pipeline (4x fewer round-trips)

Tests:

  • Added test asserting Order.aggregate is called exactly once when fetching stats
  • All 7 integration tests pass with no regressions

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 5, 2026

Someone is attempting to deploy a commit to the adithyansubramani1-1657's projects Team on Vercel.

A member of the Team first needs to authorize 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.

1 participant