Amélioration des preformances des requêtes
This commit is contained in:
parent
0bdd8693ec
commit
ed2f530f0c
@ -242,7 +242,7 @@ class CalendarList:
|
||||
Q(other_versions__isnull=True) |
|
||||
Q(other_versions__representative=F('pk')) |
|
||||
Q(other_versions__representative__isnull=True)
|
||||
).order_by("start_time", "title__unaccent__lower").prefetch_related("exact_location").prefetch_related("category").prefetch_related("other_versions")
|
||||
).order_by("start_time", "title__unaccent__lower").prefetch_related("exact_location").prefetch_related("category").prefetch_related("other_versions").prefetch_related("other_versions__representative")
|
||||
|
||||
firstdate = datetime.fromordinal(self.c_firstdate.toordinal())
|
||||
if firstdate.tzinfo is None or firstdate.tzinfo.utcoffset(firstdate) is None:
|
||||
|
@ -65,8 +65,7 @@
|
||||
<li>
|
||||
<div>
|
||||
{% if perms.agenda_culturel.view_recurrentimport %}
|
||||
{% show_badge_rimports "bottom" "failed" %}
|
||||
{% show_badge_rimports "bottom" "running" %}
|
||||
{% show_badges_rimports "bottom" %}
|
||||
{% endif %}
|
||||
{% if perms.agenda_culturel.change_event %}
|
||||
{% show_badges_events "bottom" %}
|
||||
|
@ -2,7 +2,7 @@ from django import template
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.urls import reverse_lazy
|
||||
from django.template.defaultfilters import pluralize
|
||||
from django.db.models import OuterRef, Subquery
|
||||
from django.db.models import OuterRef, Subquery, Count
|
||||
|
||||
|
||||
from agenda_culturel.models import RecurrentImport, BatchImportation
|
||||
@ -11,46 +11,54 @@ from .utils_extra import picto_from_name
|
||||
|
||||
register = template.Library()
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def badge_rimport(status, nb, suffix, picto, cl, placement):
|
||||
return ('<a href="'
|
||||
+ reverse_lazy("recurrent_imports_status", args=[status])
|
||||
+ '" class="badge ' + cl + '" data-placement="'
|
||||
+ placement
|
||||
+ '" data-tooltip="'
|
||||
+ str(nb)
|
||||
+ " importation"
|
||||
+ pluralize(nb)
|
||||
+ " récurrente"
|
||||
+ pluralize(nb)
|
||||
+ ' ' + suffix + '">'
|
||||
+ picto_from_name(picto)
|
||||
+ " "
|
||||
+ str(nb)
|
||||
+ "</a>")
|
||||
|
||||
@register.simple_tag
|
||||
def show_badge_rimports(placement, status):
|
||||
def show_badges_rimports(placement):
|
||||
newest = BatchImportation.objects.filter(recurrentImport=OuterRef("pk")).order_by(
|
||||
"-created_date"
|
||||
)
|
||||
nb = (
|
||||
RecurrentImport.objects.annotate(
|
||||
request = RecurrentImport.objects.annotate(
|
||||
last_run_status=Subquery(newest.values("status")[:1])
|
||||
)
|
||||
.filter(last_run_status=status)
|
||||
.count()
|
||||
)
|
||||
).values("last_run_status").annotate(nb_last_run_by_status=Count("last_run_status"))
|
||||
|
||||
if status == BatchImportation.STATUS.FAILED:
|
||||
suffix = 'en erreur'
|
||||
picto = "alert-triangle"
|
||||
cl = "error"
|
||||
else:
|
||||
suffix = ' en cours'
|
||||
picto = "refresh-cw"
|
||||
cl = "simple"
|
||||
|
||||
if nb != 0:
|
||||
return mark_safe(
|
||||
'<a href="'
|
||||
+ reverse_lazy("recurrent_imports_status", args=[status])
|
||||
+ '" class="badge ' + cl + '" data-placement="'
|
||||
+ placement
|
||||
+ '" data-tooltip="'
|
||||
+ str(nb)
|
||||
+ " importation"
|
||||
+ pluralize(nb)
|
||||
+ " récurrente"
|
||||
+ pluralize(nb)
|
||||
+ ' ' + suffix + '">'
|
||||
+ picto_from_name(picto)
|
||||
+ " "
|
||||
+ str(nb)
|
||||
+ "</a>"
|
||||
)
|
||||
else:
|
||||
return ""
|
||||
nbs = {}
|
||||
for res in request:
|
||||
nbs[res["last_run_status"]] = res["nb_last_run_by_status"]
|
||||
|
||||
result = ""
|
||||
|
||||
for status in ["failed", "running"]:
|
||||
if status in nbs and nbs[status] != 0:
|
||||
if status == "failed":
|
||||
suffix = 'en erreur'
|
||||
picto = "alert-triangle"
|
||||
cl = "error"
|
||||
else:
|
||||
suffix = ' en cours'
|
||||
picto = "refresh-cw"
|
||||
cl = "simple"
|
||||
result += badge_rimport(status, nbs[status], suffix, picto, cl, placement)
|
||||
|
||||
return mark_safe(result)
|
||||
|
@ -53,7 +53,7 @@ def tag_not_in_db(tag, tags):
|
||||
@register.simple_tag
|
||||
def show_suggested_tags(filter):
|
||||
filter.form.full_clean()
|
||||
tags = Tag.objects.all().filter(principal=True).order_by("name")
|
||||
tags = Tag.objects.all().filter(principal=True).order_by("name").prefetch_related("category")
|
||||
result = "Suggestion :"
|
||||
|
||||
for t in tags:
|
||||
|
Loading…
x
Reference in New Issue
Block a user