Skip to content

Commit

Permalink
Merge pull request #1362 from open-zaak/feature/zaken_pagination
Browse files Browse the repository at this point in the history
optimize list zaken
  • Loading branch information
sergei-maertens committed Apr 21, 2023
2 parents 0f17e39 + f7185b0 commit 3b88d18
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/openzaak/components/zaken/api/pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: EUPL-1.2
# Copyright (C) 2023 Dimpact
from django.core.paginator import Paginator as DjangoPaginator
from django.utils.functional import cached_property

from rest_framework.pagination import PageNumberPagination


class ZaakPaginator(DjangoPaginator):
@cached_property
def count(self):
"""
⚡ restricts values to PK to remove implicit join from SQL query
"""
return self.object_list.values("pk").count()


class ZaakPagination(PageNumberPagination):
django_paginator_class = ZaakPaginator
3 changes: 2 additions & 1 deletion src/openzaak/components/zaken/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
)
from .kanalen import KANAAL_ZAKEN
from .mixins import ClosedZaakMixin
from .pagination import ZaakPagination
from .permissions import ZaakAuthRequired, ZaakNestedAuthRequired
from .scopes import (
SCOPE_STATUSSEN_TOEVOEGEN,
Expand Down Expand Up @@ -242,7 +243,7 @@ class ZaakViewSet(
filterset_class = ZaakFilter
ordering_fields = ("startdatum",)
lookup_field = "uuid"
pagination_class = PageNumberPagination
pagination_class = ZaakPagination

permission_classes = (ZaakAuthRequired,)
required_scopes = {
Expand Down

0 comments on commit 3b88d18

Please sign in to comment.