Override the default admin queryset for some models
Because some attributes are optional or otherwise not auto-magically picked up by Django, we can help the performance of loading these pages a lot by forcing a select_related() on the queryset used by the admin. For something like signoff_specifications, this drops the query count from ~107 to 9 queries. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
2c958511c4
commit
85dc9d6df9
@ -3,6 +3,7 @@
|
||||
from .models import (PackageRelation, FlagRequest,
|
||||
Signoff, SignoffSpecification, Update)
|
||||
|
||||
|
||||
class PackageRelationAdmin(admin.ModelAdmin):
|
||||
list_display = ('pkgbase', 'user', 'type', 'created')
|
||||
list_filter = ('type', 'user')
|
||||
@ -19,6 +20,10 @@ class FlagRequestAdmin(admin.ModelAdmin):
|
||||
ordering = ('-created',)
|
||||
date_hierarchy = 'created'
|
||||
|
||||
def queryset(self, request):
|
||||
qs = super(FlagRequestAdmin, self).queryset(request)
|
||||
return qs.select_related('repo', 'user')
|
||||
|
||||
|
||||
class SignoffAdmin(admin.ModelAdmin):
|
||||
list_display = ('pkgbase', 'full_version', 'arch', 'repo',
|
||||
@ -28,6 +33,7 @@ class SignoffAdmin(admin.ModelAdmin):
|
||||
ordering = ('-created',)
|
||||
date_hierarchy = 'created'
|
||||
|
||||
|
||||
class SignoffSpecificationAdmin(admin.ModelAdmin):
|
||||
list_display = ('pkgbase', 'full_version', 'arch', 'repo',
|
||||
'user', 'created', 'comments')
|
||||
@ -36,6 +42,10 @@ class SignoffSpecificationAdmin(admin.ModelAdmin):
|
||||
ordering = ('-created',)
|
||||
date_hierarchy = 'created'
|
||||
|
||||
def queryset(self, request):
|
||||
qs = super(SignoffSpecificationAdmin, self).queryset(request)
|
||||
return qs.select_related('arch', 'repo', 'user')
|
||||
|
||||
|
||||
class UpdateAdmin(admin.ModelAdmin):
|
||||
list_display = ('pkgname', 'repo', 'arch', 'action_flag',
|
||||
|
Loading…
Reference in New Issue
Block a user