Skip to content

perf: add mongodb indexes to prevent dashboard collscan#205

Open
Unnati1007 wants to merge 1 commit into
vanshaggarwal27:mainfrom
Unnati1007:fix/mongo-indexes
Open

perf: add mongodb indexes to prevent dashboard collscan#205
Unnati1007 wants to merge 1 commit into
vanshaggarwal27:mainfrom
Unnati1007:fix/mongo-indexes

Conversation

@Unnati1007

@Unnati1007 Unnati1007 commented Jun 8, 2026

Copy link
Copy Markdown

Description

This PR resolves the severe latency and CPU load issue caused by unindexed queries in the /dashboard/history and /dashboard/stats backend endpoints.

  • Added an async MongoDB index creation block to the FastAPI lifespan startup event in backend/main.py.
  • Created a compound index on user_email (ascending) and date (descending) for the problem_info collection to ensure instant pagination.
  • Created a unique index on email (ascending) for the users collection to guarantee fast lookups.
  • Resolved IDE and runtime initialization scoping warnings by properly hoisting mongo_client and db.
  • Restored missing critical imports (PlatformCredential, encrypt, resolve_user_credentials) to prevent runtime crashes during authentication.

Related Issue #185

Type of Change

  • Bug fix
  • New feature (Performance Optimization)
  • Documentation update

Checklist

  • My code follows project guidelines
  • I have tested my changes
  • Documentation updated if needed

@Unnati1007

Copy link
Copy Markdown
Author

@vanshaggarwal27 please review the pr and assign me the issue i raised

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