Skip to content

Add indexes on created/modified for timestamped models (#891)#921

Open
vjpixel wants to merge 1 commit intodevelopfrom
claude/fix-891-db-indexes
Open

Add indexes on created/modified for timestamped models (#891)#921
vjpixel wants to merge 1 commit intodevelopfrom
claude/fix-891-db-indexes

Conversation

@vjpixel
Copy link
Copy Markdown
Member

@vjpixel vjpixel commented Apr 25, 2026

Declare Meta.indexes on all 8 TimeStampedModel-inheriting models (Sound, Marker, Object, Artwork, Exhibit, Post, PostImage, Clipping) so makemigrations produces standard AddIndex operations on -created and -modified. Adds a composite (exhibit_type, -created) index on Exhibit for the filter+order pattern in user profile views. No changes to the django-extensions inheritance.

Closes #891

https://claude.ai/code/session_01XC1THLWgnGXGf5wgRhdyvB


Generated by Claude Code

Every ModelAdmin orders by -created, and blog models use
get_latest_by='modified'. Declaring these as Meta.indexes lets
makemigrations produce standard AddIndex operations without
touching the django-extensions TimeStampedModel inheritance.

Also adds a composite (exhibit_type, -created) index on Exhibit
to cover filter+order patterns in users profile views.

Closes #891

https://claude.ai/code/session_01XC1THLWgnGXGf5wgRhdyvB
Copy link
Copy Markdown
Member Author

vjpixel commented Apr 25, 2026

Self-review

Verdict: ✅

Declares Meta.indexes on all 8 TimeStampedModel-inheriting models. makemigrations produces clean AddIndex operations only — no AlterField/AlterModelOptions noise. The composite (exhibit_type, -created) index covers the filter+order pattern in users/views.py:109,112 (Exhibit.objects.filter(exhibit_type=AR/MR).order_by("-created")).

Choices documented:

  • Indexed both -created and -modified (per user direction). All ModelAdmin classes use ordering = ["-created"]; blog models use get_latest_by = "modified" for .latest() calls.
  • Standard AddIndex (not AddIndexConcurrently) — simpler, takes a brief table lock during creation. Acceptable for current data volume per user direction. Switch to concurrent if scaling later.
  • Kept TimeStampedModel inheritance and django-extensions dependency intact, contrary to the issue's original suggestion.

Verified:

  • make migrations --check --dry-run reports no further changes after the migration files are committed.
  • make migrate applies cleanly against SQLite (and prod is PostgreSQL).
  • 107 tests still pass locally; the rest fail on environmental file paths (docker mount), unrelated.

Unique: No duplicate PR.


Generated by Claude Code

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.

Performance: Missing Database Indexes

2 participants