A dirty mixin to rescue from dumb count(*)
query of Django admin
Django admin works well with less set of rows.
But it slows down on large database system - every single list page of admin needs SELECT COUNT(*) FROM TABLE
query to calculate the count of rows.
And this causes severe performance issues on production system.
We don't really want to know EXACT count of rows. Right? Then use this.
See this Stackoverflow question
pip install django-admin-approx-count
or, download / clone from source repo
Use shipped mixins in your admin.py
.
from django.contrib import admin
from approx_count.mixin import MaxIdAdminMixin, TableStatusAdminMixin
class SomeAdmin(MaxIdAdminMixin, admin.ModelAdmin):
...
class AnotherAdmin(TableStatusAdminMixin, admin.ModelAdmin):
...
Or, with admin classes.
from approx_count.admin import MaxIdModelAdmin, TableStatusModelAdmin
class SomeAdmin(MaxIdModelAdmin):
...
class AnotherAdmin(TableStatusModelAdmin):
...
Default django queryset uses SELECT COUNT(*) FROM TABLE
to calculate row count. However,
MaxIdAdminMixin
usesSELECT MAX(ID) FROM TABLE
.TableStatusAdminMixin
uses table status / information.
- For MySQL, by Nova
- For Postgres, by Woody Anderson
Park Hyunwoo(@lqez)
django-admin-approx-count
is distributed under MIT license.