mirror of
https://github.com/daniviga/django-ram.git
synced 2026-02-04 10:00:40 +01:00
Add more indexes and optimize usage
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
# Generated by Django 6.0.1 on 2026-01-18 13:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("consist", "0019_consistitem_load"),
|
||||
(
|
||||
"metadata",
|
||||
"0027_company_company_slug_idx_company_company_country_idx_and_more",
|
||||
),
|
||||
("roster", "0041_rollingclass_roster_rc_company_idx_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddIndex(
|
||||
model_name="consist",
|
||||
index=models.Index(fields=["published"], name="consist_published_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="consist",
|
||||
index=models.Index(fields=["scale"], name="consist_scale_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="consist",
|
||||
index=models.Index(fields=["company"], name="consist_company_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="consist",
|
||||
index=models.Index(
|
||||
fields=["published", "scale"], name="consist_pub_scale_idx"
|
||||
),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="consistitem",
|
||||
index=models.Index(fields=["load"], name="consist_item_load_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="consistitem",
|
||||
index=models.Index(fields=["order"], name="consist_item_order_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="consistitem",
|
||||
index=models.Index(
|
||||
fields=["consist", "load"], name="consist_item_con_load_idx"
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -74,6 +74,18 @@ class Consist(BaseModel):
|
||||
|
||||
class Meta:
|
||||
ordering = ["company", "-creation_time"]
|
||||
indexes = [
|
||||
# Index for published filtering
|
||||
models.Index(fields=["published"], name="consist_published_idx"),
|
||||
# Index for scale filtering
|
||||
models.Index(fields=["scale"], name="consist_scale_idx"),
|
||||
# Index for company filtering
|
||||
models.Index(fields=["company"], name="consist_company_idx"),
|
||||
# Composite index for published+scale filtering
|
||||
models.Index(
|
||||
fields=["published", "scale"], name="consist_pub_scale_idx"
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
class ConsistItem(models.Model):
|
||||
@@ -89,9 +101,19 @@ class ConsistItem(models.Model):
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["consist", "rolling_stock"],
|
||||
name="one_stock_per_consist"
|
||||
name="one_stock_per_consist",
|
||||
)
|
||||
]
|
||||
indexes = [
|
||||
# Index for filtering by load status
|
||||
models.Index(fields=["load"], name="consist_item_load_idx"),
|
||||
# Index for ordering
|
||||
models.Index(fields=["order"], name="consist_item_order_idx"),
|
||||
# Composite index for consist+load filtering
|
||||
models.Index(
|
||||
fields=["consist", "load"], name="consist_item_con_load_idx"
|
||||
),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return "{0}".format(self.rolling_stock)
|
||||
|
||||
Reference in New Issue
Block a user