Skip to content

Commit

Permalink
perf(hearing): optimize open filter
Browse files Browse the repository at this point in the history
Replace union & distinct with or statements.

Refs KER-366
  • Loading branch information
danipran committed May 28, 2024
1 parent 84b3084 commit de0b166
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions democracy/views/hearing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections import defaultdict
from django.conf import settings
from django.db import transaction
from django.db.models import Prefetch
from django.db.models import Prefetch, Q
from django.utils import timezone
from rest_framework import filters, permissions, response, serializers, status, viewsets
from rest_framework.decorators import action
Expand Down Expand Up @@ -68,11 +68,9 @@ def filter_open(self, queryset, name, value):
.filter(force_closed=False)
)
else:
return (
queryset.filter(close_at__lte=timezone.now())
| queryset.filter(open_at__gt=timezone.now())
| queryset.filter(force_closed=True)
).distinct()
return queryset.filter(
Q(close_at__lte=timezone.now()) | Q(open_at__gt=timezone.now()) | Q(force_closed=True)
)

def filter_created_by(self, queryset, name, value):
if not self.request.user:
Expand Down

0 comments on commit de0b166

Please sign in to comment.