mirror of
https://github.com/daniviga/django-ram.git
synced 2026-02-04 01:50:39 +01:00
Improve performance oprimizing queries (#56)
* Extend test coverage * Implement query optimization * More aggressing code reuse * Add more indexes and optimize usage * Fix tests * Further optimizations, improve counting to rely on backend DB * chore: add Makefile for frontend asset minification - Add comprehensive Makefile with targets for JS and CSS minification - Implements instructions from ram/portal/static/js/src/README.md - Provides targets: install, minify, minify-js, minify-css, clean, watch - Fix main.min.js to only include theme_selector.js and tabs_selector.js - Remove validators.js from minified output per README instructions * Add a Makefile to compile JS and CSS * docs: add blank line whitespace rule to AGENTS.md Specify that blank lines must not contain any whitespace (spaces or tabs) to maintain code cleanliness and PEP 8 compliance * Update for 0.20 release with optimizations * Improve Makefile
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
# Generated by Django 6.0.1 on 2026-01-18 13:42
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("metadata", "0026_alter_manufacturer_name_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddIndex(
|
||||
model_name="company",
|
||||
index=models.Index(fields=["slug"], name="company_slug_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="company",
|
||||
index=models.Index(fields=["country"], name="company_country_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="company",
|
||||
index=models.Index(fields=["freelance"], name="company_freelance_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="manufacturer",
|
||||
index=models.Index(fields=["category"], name="mfr_category_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="manufacturer",
|
||||
index=models.Index(fields=["slug"], name="mfr_slug_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="manufacturer",
|
||||
index=models.Index(fields=["category", "slug"], name="mfr_cat_slug_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="scale",
|
||||
index=models.Index(fields=["slug"], name="scale_slug_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="scale",
|
||||
index=models.Index(fields=["ratio_int"], name="scale_ratio_idx"),
|
||||
),
|
||||
migrations.AddIndex(
|
||||
model_name="scale",
|
||||
index=models.Index(
|
||||
fields=["-ratio_int", "-tracks"], name="scale_ratio_tracks_idx"
|
||||
),
|
||||
),
|
||||
]
|
||||
@@ -48,10 +48,19 @@ class Manufacturer(SimpleBaseModel):
|
||||
ordering = ["category", "slug"]
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["name", "category"],
|
||||
name="unique_name_category"
|
||||
fields=["name", "category"], name="unique_name_category"
|
||||
)
|
||||
]
|
||||
indexes = [
|
||||
# Index for category filtering
|
||||
models.Index(fields=["category"], name="mfr_category_idx"),
|
||||
# Index for slug lookups
|
||||
models.Index(fields=["slug"], name="mfr_slug_idx"),
|
||||
# Composite index for category+slug (already in ordering)
|
||||
models.Index(
|
||||
fields=["category", "slug"], name="mfr_cat_slug_idx"
|
||||
),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@@ -91,6 +100,14 @@ class Company(SimpleBaseModel):
|
||||
class Meta:
|
||||
verbose_name_plural = "Companies"
|
||||
ordering = ["slug"]
|
||||
indexes = [
|
||||
# Index for slug lookups (used frequently in URLs)
|
||||
models.Index(fields=["slug"], name="company_slug_idx"),
|
||||
# Index for country filtering
|
||||
models.Index(fields=["country"], name="company_country_idx"),
|
||||
# Index for freelance filtering
|
||||
models.Index(fields=["freelance"], name="company_freelance_idx"),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
@@ -165,6 +182,16 @@ class Scale(SimpleBaseModel):
|
||||
|
||||
class Meta:
|
||||
ordering = ["-ratio_int", "-tracks", "scale"]
|
||||
indexes = [
|
||||
# Index for slug lookups
|
||||
models.Index(fields=["slug"], name="scale_slug_idx"),
|
||||
# Index for ratio_int ordering and filtering
|
||||
models.Index(fields=["ratio_int"], name="scale_ratio_idx"),
|
||||
# Composite index for common ordering pattern
|
||||
models.Index(
|
||||
fields=["-ratio_int", "-tracks"], name="scale_ratio_tracks_idx"
|
||||
),
|
||||
]
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse(
|
||||
|
||||
Reference in New Issue
Block a user