Skip to content

[BE-86] Database index audit on foreign keys and hot query paths #1474

Description

@yusuftomilola

Overview

Entities across ~20 modules define relations, but there is no evidence of a deliberate indexing pass. Booking conflict checks, availability lookups, and dashboard aggregations all filter on columns that are likely unindexed — these degrade sharply as data grows.

Tasks

  • Inventory the slowest/most frequent queries: booking overlap checks, availability by workspace + date range, attendance by user + date, invoice by user + status, notifications by user + read state.
  • Add @Index() declarations, including composite indexes matching real filter order (e.g. (workspaceId, startTime, endTime)).
  • Ensure every foreign key column has an index — Postgres does not create these automatically.
  • Add partial indexes where predicates are selective (e.g. unread notifications).
  • Generate a migration and record EXPLAIN ANALYZE before/after in the PR.

Acceptance Criteria

  • Migration adds the indexes and runs cleanly.
  • The PR shows measured improvement on at least three representative queries against a seeded dataset.
  • No sequential scans remain on the booking-overlap query.

Notes for Contributors

Comment below to be assigned.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions