Skip to content

Commit

Permalink
Optimise query in the events admin detail page (#174)
Browse files Browse the repository at this point in the history
When we select a record to display in the all events admin, we can optimise the query not to UNION other event tables but stick to the original table only.

Type: feature
  • Loading branch information
lokhman authored Nov 1, 2024
1 parent 0abe20d commit d590ccd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pghistory/admin/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import django
from django.apps import apps
from django.contrib import admin
from django.contrib.admin.utils import unquote
from django.contrib.admin.views.main import ChangeList
from django.utils.encoding import force_str

from pghistory import config, core
from pghistory import config, core, models


def _get_model(model):
Expand Down Expand Up @@ -227,4 +228,11 @@ def get_list_filter(self, request):
return filters

def get_queryset(self, request):
return config.admin_queryset()
queryset = config.admin_queryset()
if isinstance(queryset, models.EventsQuerySet):
object_id = request.resolver_match.kwargs.get("object_id")
if object_id is not None:
target_model = _get_model(unquote(object_id).partition(":")[0])
if target_model:
queryset = queryset.across(target_model)
return queryset

0 comments on commit d590ccd

Please sign in to comment.