Skip to content

Commit 5ce596c

Browse files
authored
admin speedup: defer big json fields to optimise the admin list page (#38)
The list of objects in django admin doesn't use the big jsons fields, so it's okay to defer them. This makes for a significant speed up as some of the JSONs are a few MB in size, and loading a list of 50 or a 100 (one page) of those objects would mean 100s of MB more data to read from the database that is then not even used.
1 parent b1acc0e commit 5ce596c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

intbot/core/admin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class PretalxDataAdmin(admin.ModelAdmin):
8787
"processed_at",
8888
]
8989

90+
def get_queryset(self, request):
91+
qs = super().get_queryset(request)
92+
qs = qs.defer("content")
93+
return qs
94+
9095
def pretty_content(self, obj: PretalxData):
9196
return format_html("<pre>{}</pre>", json.dumps(obj.content, indent=4))
9297

@@ -113,6 +118,11 @@ class PretixDataAdmin(admin.ModelAdmin):
113118
"processed_at",
114119
]
115120

121+
def get_queryset(self, request):
122+
qs = super().get_queryset(request)
123+
qs = qs.defer("content")
124+
return qs
125+
116126
def pretty_content(self, obj: PretixData):
117127
return format_html("<pre>{}</pre>", json.dumps(obj.content, indent=4))
118128

0 commit comments

Comments
 (0)