-
Notifications
You must be signed in to change notification settings - Fork 8
Add composite database indexes for gallery queries #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Generated by Django 6.0.3 on 2026-04-10 23:25 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('data', '0024_image_rating_default'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddIndex( | ||
| model_name='fujifilmrecipe', | ||
| index=models.Index(fields=['film_simulation'], name='idx_recipe_film_sim'), | ||
| ), | ||
| migrations.AddIndex( | ||
| model_name='image', | ||
| index=models.Index(fields=['-taken_at', 'id'], name='idx_image_taken_id'), | ||
| ), | ||
| migrations.AddIndex( | ||
| model_name='image', | ||
| index=models.Index(fields=['-rating', '-taken_at', 'id'], name='idx_image_rating_taken'), | ||
| ), | ||
| migrations.AddIndex( | ||
| model_name='image', | ||
| index=models.Index(fields=['fujifilm_recipe', '-rating', '-taken_at'], name='idx_image_recipe_rating'), | ||
| ), | ||
| migrations.AddIndex( | ||
| model_name='image', | ||
| index=models.Index(fields=['is_favorite', '-taken_at'], name='idx_image_favorite_taken'), | ||
| ), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -188,6 +188,9 @@ class FujifilmRecipe(models.Model): | |
| monochromatic_color_magenta_green = models.DecimalField(max_digits=4, decimal_places=1, null=True, blank=True) | ||
|
|
||
| class Meta: | ||
| indexes = [ | ||
| models.Index(fields=["film_simulation"], name="idx_recipe_film_sim"), | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (suggestion): The |
||
| ] | ||
| constraints = [ | ||
| models.UniqueConstraint( | ||
| fields=[ | ||
|
|
@@ -316,6 +319,12 @@ class Image(models.Model): | |
| rating = models.IntegerField(default=0) | ||
|
|
||
| class Meta: | ||
| indexes = [ | ||
| models.Index(fields=["-taken_at", "id"], name="idx_image_taken_id"), | ||
| models.Index(fields=["-rating", "-taken_at", "id"], name="idx_image_rating_taken"), | ||
| models.Index(fields=["fujifilm_recipe", "-rating", "-taken_at"], name="idx_image_recipe_rating"), | ||
| models.Index(fields=["is_favorite", "-taken_at"], name="idx_image_favorite_taken"), | ||
| ] | ||
| constraints = [ | ||
| models.UniqueConstraint(fields=["filepath"], name="unique_image_filepath"), | ||
| ] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(question)[non-blocking]: This migration is safe to skip for non-developer users since a missing index will not break the app. However, it is a good reminder that we need a way for users who just want to run the project to apply migrations easily — e.g. a
make updatecommand that runsgit pull origin mainfollowed bypython manage.py migrate. Not required for this PR, but important to have before we ship any migration that adds or modifies fields or tables.