mirror of
https://github.com/daniviga/django-ram.git
synced 2026-02-04 01:50:39 +01:00
Add more indexes and optimize usage
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
# Generated by Django 6.0.1 on 2026-01-18 13:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookshelf", "0031_alter_tocentry_authors_alter_tocentry_subtitle_and_more"),
|
||||
(
|
||||
"metadata",
|
||||
"0027_company_company_slug_idx_company_company_country_idx_and_more",
|
||||
),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddIndex(
|
||||
model_name="book",
|
||||
index=models.Index(fields=["title"], name="book_title_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="catalog",
|
||||
index=models.Index(fields=["manufacturer"], name="catalog_mfr_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="magazine",
|
||||
index=models.Index(fields=["published"], name="magazine_published_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="magazine",
|
||||
index=models.Index(fields=["name"], name="magazine_name_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="magazineissue",
|
||||
index=models.Index(fields=["magazine"], name="mag_issue_mag_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="magazineissue",
|
||||
index=models.Index(
|
||||
fields=["publication_month"], name="mag_issue_pub_month_idx"
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -110,6 +110,12 @@ class Book(BaseBook):
|
||||
|
||||
class Meta:
|
||||
ordering = ["title"]
|
||||
indexes = [
|
||||
# Index for title searches (local field)
|
||||
models.Index(fields=["title"], name="book_title_idx"),
|
||||
# Note: published and publication_year are inherited from BaseBook/BaseModel
|
||||
# and cannot be indexed here due to multi-table inheritance
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
@@ -141,6 +147,14 @@ class Catalog(BaseBook):
|
||||
|
||||
class Meta:
|
||||
ordering = ["manufacturer", "publication_year"]
|
||||
indexes = [
|
||||
# Index for manufacturer filtering (local field)
|
||||
models.Index(
|
||||
fields=["manufacturer"], name="catalog_mfr_idx"
|
||||
),
|
||||
# Note: published and publication_year are inherited from BaseBook/BaseModel
|
||||
# and cannot be indexed here due to multi-table inheritance
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
# if the object is new, return an empty string to avoid
|
||||
@@ -189,6 +203,12 @@ class Magazine(BaseModel):
|
||||
|
||||
class Meta:
|
||||
ordering = [Lower("name")]
|
||||
indexes = [
|
||||
# Index for published filtering
|
||||
models.Index(fields=["published"], name="magazine_published_idx"),
|
||||
# Index for name searches (case-insensitive via db_collation if needed)
|
||||
models.Index(fields=["name"], name="magazine_name_idx"),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@@ -229,6 +249,17 @@ class MagazineIssue(BaseBook):
|
||||
"publication_month",
|
||||
"issue_number",
|
||||
]
|
||||
indexes = [
|
||||
# Index for magazine filtering (local field)
|
||||
models.Index(fields=["magazine"], name="mag_issue_mag_idx"),
|
||||
# Index for publication month (local field)
|
||||
models.Index(
|
||||
fields=["publication_month"],
|
||||
name="mag_issue_pub_month_idx",
|
||||
),
|
||||
# Note: published and publication_year are inherited from BaseBook/BaseModel
|
||||
# and cannot be indexed here due to multi-table inheritance
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.magazine.name} - {self.issue_number}"
|
||||
|
||||
Reference in New Issue
Block a user