Skip to content
Snippets Groups Projects
Commit 461fc03b authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Bastien Abadie
Browse files

Reduce image server statistics to three SQL queries

parent 34361e8c
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ from django.conf import settings
from django.db.models import Count
from django.utils.text import slugify
from arkindex.documents.models import Element, ElementType, Transcription, Corpus
from arkindex.images.models import ImageServer, ImageStatus
from arkindex.images.models import ImageServer, ImageStatus, Image
from urllib.parse import urljoin
import time
import requests
......@@ -64,13 +64,26 @@ class Command(BaseCommand):
with_transcriptions=vol_with_transcriptions_count.get(corpus.id, 0),
)
# Image server statistics, in three SQL queries
checked_counts = dict(
Image.objects
.filter(status=ImageStatus.Checked)
.values_list('server')
.annotate(Count('server'))
)
error_counts = dict(
Image.objects
.filter(status=ImageStatus.Error)
.values_list('server')
.annotate(Count('server'))
)
for server in ImageServer.objects.annotate(img_total=Count('images')):
self.output(
'images',
tags={'imageserver': server.grafana_tag},
total=server.img_total,
checked=server.images.filter(status=ImageStatus.Checked).count(),
errors=server.images.filter(status=ImageStatus.Error).count(),
checked=checked_counts.get(server.id, 0),
errors=error_counts.get(server.id, 0),
)
def dict_to_str(self, data):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment