Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/data/migrations/0025_add_gallery_indexes.py
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):

Copy link
Copy Markdown
Owner

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 update command that runs git pull origin main followed by python manage.py migrate. Not required for this PR, but important to have before we ship any migration that adds or modifies fields or tables.

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'),
),
]
9 changes: 9 additions & 0 deletions src/data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

(suggestion): The FujifilmRecipe table tends to stay small relative to the image catalog — recipes are unique combinations of camera settings, so the cardinality is naturally limited. For a small table, PostgreSQL's query planner may prefer a sequential scan over an index lookup, making this index add write overhead without a measurable query benefit. Worth considering whether it's needed.

]
constraints = [
models.UniqueConstraint(
fields=[
Expand Down Expand Up @@ -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"),
]
Expand Down
Loading