Skip to content
Snippets Groups Projects
Commit fd9ec32b authored by Bastien Abadie's avatar Bastien Abadie
Browse files

Merge branch 'naughty-telegraf' into 'master'

Reduce image server statistics to three SQL queries

See merge request !246
parents 34361e8c 461fc03b
No related branches found
No related tags found
1 merge request!246Reduce image server statistics to three SQL queries
......@@ -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