mirror of
https://github.com/django-helpdesk/django-helpdesk.git
synced 2025-06-05 09:16:45 +02:00
faster query for followup_date
This commit is contained in:
parent
8c27f74605
commit
01c28a4d62
@ -1,6 +1,8 @@
|
||||
|
||||
from base64 import b64decode, b64encode
|
||||
from django.db.models import Q, Max
|
||||
from django.db.models import F, Window, Subquery, OuterRef
|
||||
from .models import FollowUp
|
||||
from django.urls import reverse
|
||||
from django.utils.html import escape
|
||||
from django.utils.translation import gettext as _
|
||||
@ -175,8 +177,21 @@ class __Query__:
|
||||
# django orm '-' -> desc
|
||||
if order == 'desc':
|
||||
order_column = '-' + order_column
|
||||
|
||||
queryset = objects.annotate(last_followup=Max('followup__date')).order_by(order_by)
|
||||
|
||||
queryset = objects.annotate(
|
||||
last_followup=Subquery(
|
||||
FollowUp.objects.order_by().annotate(
|
||||
last_followup=Window(
|
||||
expression=Max("date"),
|
||||
partition_by=[F("ticket_id"),],
|
||||
order_by="-date"
|
||||
)
|
||||
).filter(
|
||||
ticket_id=OuterRef("id")
|
||||
).values("last_followup").distinct()
|
||||
)
|
||||
).order_by(order_by)
|
||||
|
||||
total = queryset.count()
|
||||
|
||||
if search_value: # Dead code currently
|
||||
|
Loading…
x
Reference in New Issue
Block a user