fix(#891): Replace TimeStampedModel inheritance with explicit fields and indexes#951
Draft
vjpixel wants to merge 1 commit into
Draft
fix(#891): Replace TimeStampedModel inheritance with explicit fields and indexes#951vjpixel wants to merge 1 commit into
vjpixel wants to merge 1 commit into
Conversation
…and indexes Remove TimeStampedModel inheritance from PostImage, Clipping, Post, Sound, Marker, Object, Artwork, and Exhibit. Declare created/modified manually with descending Meta.indexes on each model, plus a composite (exhibit_type, -created) index on Exhibit covering the filter+order pattern in users/views.py:109,112. Keeps django-extensions installed so historical migrations (blog/0008, core/0013, 0016, 0027) still replay on fresh local environments. Addresses @pablodiegoss's review on PR #921: indexing on top of the inheritance was a band-aid that locked the project into TimeStampedModel forever. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Alternative implementation of #891 addressing @pablodiegoss's review on #921.
Instead of layering
Meta.indexeson top ofTimeStampedModelinheritance (the #921 approach), this PR removes the inheritance entirely and declarescreated/modifiedmanually on each affected model. This frees the project from a forever-dependency onTimeStampedModel's shape while still adding the indexes the issue asks for.Changes
TimeStampedModelfrom 8 models:PostImage,Clipping,Post(blog),Sound,Marker,Object,Artwork,Exhibit(core).created = DateTimeField(auto_now_add=True)andmodified = DateTimeField(auto_now=True)to each.Meta.get_latest_by = "modified"(preserves migration history).Meta.indexeson-createdand-modifiedfor all 8 models.(exhibit_type, -created)index onExhibitcoveringusers/views.py:109,112and similar queries incore/views/views.py.django-extensionsinstalled (pyproject.toml,INSTALLED_APPS) so historical migrations (blog/0008,core/0013, 0016, 0027) still replay on fresh local environments.Migrations
src/blog/migrations/0010_*— 7AlterField+ 6AddIndex.src/core/migrations/0028_*— 20AlterField(10 main models + 10 pghistory event mirrors) + 11AddIndex(10 single-column + 1 composite).No
AlterModelOptions, noRemoveField/AddField. Thedisplay_dateAlterFieldin the blog migration is a benign side-effect — pre-existing model/migration drift (model declaresdb_index=True, but migration0009had dropped it) thatmakemigrationslegitimately catches up.Why this over #921
Test plan
make migrationsgenerates expected operations onlymakemigrations --dry-run --check→ "No changes detected" (idempotent)sqlmigrate core 0028against Postgres confirmsAlterFieldis metadata-only (no table rewrite). BothCreationDateTimeFieldandDateTimeFielddeconstruct totimestamp with time zone, so this should be a no-op.EXPLAIN ANALYZE SELECT * FROM core_exhibit WHERE exhibit_type='AR' ORDER BY created DESC LIMIT 10;against staging confirmsIndex Scan using exhibit_type_created_idx./admin/blog/post/,/admin/core/exhibit/,/admin/core/sound/render withcreated/modifiedcolumns and-createdordering.AddIndexlocks).Related
🤖 Generated with Claude Code