Skip to content

Commit

Permalink
Merge pull request #1380 from open-zaak/issue/1363-speedup-eio
Browse files Browse the repository at this point in the history
⚡ [#1363] Optimize EIO endpoint performance
  • Loading branch information
stevenbal committed Jun 6, 2023
2 parents 6321717 + fbd87ab commit ab0acbb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/openzaak/components/documenten/api/pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SPDX-License-Identifier: EUPL-1.2
# Copyright (C) 2023 Dimpact
from django.conf import settings
from django.core.paginator import Paginator as DjangoPaginator
from django.utils.functional import cached_property

from rest_framework.pagination import PageNumberPagination


class EnkelvoudigInformatieObjectPaginator(DjangoPaginator):
@cached_property
def count(self):
"""
⚡ restricts values to PK to remove implicit join from SQL query
"""
if not settings.CMIS_ENABLED:
# Objects in CMISQuerySet do not have `pk`s
return self.object_list.values("pk").count()
return super().count


class EnkelvoudigInformatieObjectPagination(PageNumberPagination):
django_paginator_class = EnkelvoudigInformatieObjectPaginator
5 changes: 3 additions & 2 deletions src/openzaak/components/documenten/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from notifications_api_common.viewsets import NotificationViewSetMixin
from rest_framework import mixins, status, viewsets
from rest_framework.decorators import action
from rest_framework.pagination import PageNumberPagination
from rest_framework.parsers import FormParser, MultiPartParser
from rest_framework.response import Response
from rest_framework.serializers import ValidationError
Expand Down Expand Up @@ -44,6 +43,7 @@
)
from .kanalen import KANAAL_DOCUMENTEN
from .mixins import UpdateWithoutPartialMixin
from .pagination import EnkelvoudigInformatieObjectPagination
from .permissions import InformationObjectAuthRequired
from .renderers import BinaryFileRenderer
from .scopes import (
Expand Down Expand Up @@ -187,12 +187,13 @@ class EnkelvoudigInformatieObjectViewSet(
EnkelvoudigInformatieObject.objects.select_related(
"canonical", "_informatieobjecttype"
)
.prefetch_related("canonical__bestandsdelen")
.order_by("canonical", "-versie")
.distinct("canonical")
)
lookup_field = "uuid"
serializer_class = EnkelvoudigInformatieObjectSerializer
pagination_class = PageNumberPagination
pagination_class = EnkelvoudigInformatieObjectPagination
permission_classes = (InformationObjectAuthRequired,)
required_scopes = {
"list": SCOPE_DOCUMENTEN_ALLES_LEZEN,
Expand Down

0 comments on commit ab0acbb

Please sign in to comment.