]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
simplify character count query
authorshamoon <4887959+shamoon@users.noreply.github.com>
Sat, 18 Mar 2023 21:31:27 +0000 (14:31 -0700)
committershamoon <4887959+shamoon@users.noreply.github.com>
Sat, 18 Mar 2023 21:31:27 +0000 (14:31 -0700)
Co-Authored-By: Trenton H <797416+stumpylog@users.noreply.github.com>
src/documents/views.py

index ede5e0d90d7228b8725b69e815f3b4c72f0e5aa6..9a47d928d6ca6547a89975471e22945eaeae1727 100644 (file)
@@ -20,6 +20,7 @@ from django.db.models import Case
 from django.db.models import Count
 from django.db.models import IntegerField
 from django.db.models import Max
+from django.db.models import Sum
 from django.db.models import When
 from django.db.models.functions import Length
 from django.db.models.functions import Lower
@@ -814,14 +815,11 @@ class StatisticsView(APIView):
         )
 
         character_count = (
-            sum(
-                Document.objects.annotate(characters=Length("content")).values_list(
-                    "characters",
-                    flat=True,
-                ),
+            Document.objects.annotate(
+                characters=Length("content"),
             )
-            if documents_total > 0
-            else 0
+            .aggregate(Sum("characters"))
+            .get("characters__sum")
         )
 
         return Response(