mirror of
https://github.com/daniviga/django-ram.git
synced 2026-02-04 10:00:40 +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:
@@ -158,6 +158,11 @@ class RollingStockAdmin(SortableAdminBase, admin.ModelAdmin):
|
||||
)
|
||||
save_as = True
|
||||
|
||||
def get_queryset(self, request):
|
||||
"""Optimize queryset with select_related and prefetch_related."""
|
||||
qs = super().get_queryset(request)
|
||||
return qs.with_related()
|
||||
|
||||
@admin.display(description="Country")
|
||||
def country_flag(self, obj):
|
||||
return format_html(
|
||||
@@ -268,6 +273,18 @@ class RollingStockAdmin(SortableAdminBase, admin.ModelAdmin):
|
||||
"Properties",
|
||||
]
|
||||
data = []
|
||||
|
||||
# Prefetch related data to avoid N+1 queries
|
||||
queryset = queryset.select_related(
|
||||
'rolling_class',
|
||||
'rolling_class__type',
|
||||
'rolling_class__company',
|
||||
'manufacturer',
|
||||
'scale',
|
||||
'decoder',
|
||||
'shop'
|
||||
).prefetch_related('tags', 'property__property')
|
||||
|
||||
for obj in queryset:
|
||||
properties = settings.CSV_SEPARATOR_ALT.join(
|
||||
"{}:{}".format(property.property.name, property.value)
|
||||
|
||||
Reference in New Issue
Block a user