Skip to content

Add more non-unique indices for read performance#845

Open
julianweng wants to merge 3 commits into
masterfrom
add-indices-oct-2025
Open

Add more non-unique indices for read performance#845
julianweng wants to merge 3 commits into
masterfrom
add-indices-oct-2025

Conversation

@julianweng
Copy link
Copy Markdown
Member

@julianweng julianweng commented Oct 2, 2025

Asked Claude Code to read through our read queries and add indices as recommended. In general, the app is read-heavy (or at the very least write-light with the possible exception of applications, but even then the degraded application write performance seemed to be from system-wide constraints), so adding these queries is low risk from a performance standpoint. However, these could increase storage costs somewhat.

Here is the list of indices + usages it came up with:

Database Index Changes (vs master)

Club Model

  • archived — Excludes archived clubs (views.py:1224)
  • approved_on — Existing index for approval date queries
  • (approved, archived) — Combined filtering for active, non-archived clubs (views.py:1224)
  • Removed: approved (single-column; covered by composite and low selectivity) (views.py:1234)

Event Model

EventShowing Model

ClubFair Model

  • end_time — Current/active fair filtering (views.py:699)
  • (end_time, start_time) — Composite to support upcoming/current lists and ordering (views.py:1096)

Membership Model

  • role — Officer/member permission checks (views.py:2471)
  • Removed: (person, club, role) — Low benefit given existing unique (club, person) and observed query patterns

ClubVisit Model

  • (club, visit_type, created_at) — Time-series visit analytics (views.py:1637)
  • Removed: visit_type (single-column; analytics use composite)

ClubApplication Model

  • application_start_time — Application period filtering (views.py:7343)
  • application_end_time — Deadline checking (views.py:7343)
  • result_release_time — Result release scheduling

ApplicationSubmission Model

  • status — Filter/aggregate by acceptance/rejection status (views.py:7714)

Ticket Model

  • type — Ticket type filtering (views.py:3494)
  • (showing, type) — Available tickets by type per showing (views.py:3494)
  • (showing, owner) — Ticket ownership queries (views.py:3333)
  • (showing, holder) — Held ticket queries
  • (showing, type) WHERE owner IS NULL AND holder IS NULL AND buyable = TRUE — Partial index for fast “available tickets” lookups (views.py:3493)

Badge Model

@julianweng julianweng requested a review from Copilot October 2, 2025 16:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds database indices to improve read performance across multiple models in the penn-clubs application. The changes focus on fields that are frequently used in filtering, ordering, and JOIN operations based on analysis of existing query patterns.

  • Adds single-field indices on boolean and datetime fields used for filtering
  • Creates composite indices for commonly combined filter conditions
  • Targets models like Club, Event, Membership, and Ticket that are central to the application's read-heavy workload

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread backend/clubs/models.py Outdated

class Meta:
indexes = [
models.Index(fields=["event", "start_time"]),
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The composite index on ['event', 'start_time'] may be redundant since 'event' is already a ForeignKey which typically has an implicit index. Consider whether a single-field index on 'start_time' would be sufficient for the query patterns, or if the composite index provides additional optimization for specific queries that filter by both event and start_time together.

Suggested change
models.Index(fields=["event", "start_time"]),

Copilot uses AI. Check for mistakes.
Comment thread backend/clubs/models.py
Comment thread backend/clubs/models.py Outdated
@julianweng julianweng requested a review from Copilot October 2, 2025 16:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.60%. Comparing base (6737000) to head (3728c0c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #845      +/-   ##
==========================================
+ Coverage   74.57%   74.60%   +0.02%     
==========================================
  Files          33       33              
  Lines        7852     7861       +9     
==========================================
+ Hits         5856     5865       +9     
  Misses       1996     1996              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@julianweng julianweng requested a review from Porcupine1 October 2, 2025 16:37
@julianweng julianweng requested a review from Copilot October 2, 2025 17:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread backend/clubs/models.py
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.

2 participants