From 504198b14f8769f89182584287f6d0b4347380de Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Wed, 11 Dec 2024 20:16:08 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liorations=20des=20performances?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agenda_culturel/calendar.py | 3 +- ...agenda_cult_end_day_4660a5_idx_and_more.py | 25 ++++++++ .../migrations/0128_event_datetimes_title.py | 18 ++++++ ...agenda_cult_created_a23990_idx_and_more.py | 57 +++++++++++++++++++ src/agenda_culturel/models.py | 41 +++++++++---- .../templates/agenda_culturel/page-event.html | 34 +---------- src/agenda_culturel/views.py | 2 + 7 files changed, 133 insertions(+), 47 deletions(-) create mode 100644 src/agenda_culturel/migrations/0127_event_agenda_cult_end_day_4660a5_idx_and_more.py create mode 100644 src/agenda_culturel/migrations/0128_event_datetimes_title.py create mode 100644 src/agenda_culturel/migrations/0129_batchimportation_agenda_cult_created_a23990_idx_and_more.py diff --git a/src/agenda_culturel/calendar.py b/src/agenda_culturel/calendar.py index 940a6b8..aa110f6 100644 --- a/src/agenda_culturel/calendar.py +++ b/src/agenda_culturel/calendar.py @@ -266,8 +266,7 @@ class CalendarList: Q(other_versions__representative__isnull=True) ).order_by("start_time", "title__unaccent__lower") - if self.qs is None: - qs = qs.select_related("exact_location").select_related("category").select_related("other_versions").select_related("other_versions__representative") + qs = qs.select_related("exact_location").select_related("category").select_related("other_versions").select_related("other_versions__representative") self.events = qs firstdate = datetime.fromordinal(self.c_firstdate.toordinal()) diff --git a/src/agenda_culturel/migrations/0127_event_agenda_cult_end_day_4660a5_idx_and_more.py b/src/agenda_culturel/migrations/0127_event_agenda_cult_end_day_4660a5_idx_and_more.py new file mode 100644 index 0000000..d241af1 --- /dev/null +++ b/src/agenda_culturel/migrations/0127_event_agenda_cult_end_day_4660a5_idx_and_more.py @@ -0,0 +1,25 @@ +# Generated by Django 4.2.9 on 2024-12-11 19:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('agenda_culturel', '0126_message_user'), + ] + + operations = [ + migrations.AddIndex( + model_name='event', + index=models.Index(fields=['end_day', 'end_time'], name='agenda_cult_end_day_4660a5_idx'), + ), + migrations.AddIndex( + model_name='event', + index=models.Index(fields=['status'], name='agenda_cult_status_893243_idx'), + ), + migrations.AddIndex( + model_name='event', + index=models.Index(fields=['recurrence_dtstart', 'recurrence_dtend'], name='agenda_cult_recurre_a8911c_idx'), + ), + ] diff --git a/src/agenda_culturel/migrations/0128_event_datetimes_title.py b/src/agenda_culturel/migrations/0128_event_datetimes_title.py new file mode 100644 index 0000000..2b0ca51 --- /dev/null +++ b/src/agenda_culturel/migrations/0128_event_datetimes_title.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.9 on 2024-12-11 19:12 + +from django.db import migrations, models +import django.db.models.functions.text + + +class Migration(migrations.Migration): + + dependencies = [ + ('agenda_culturel', '0127_event_agenda_cult_end_day_4660a5_idx_and_more'), + ] + + operations = [ + migrations.AddIndex( + model_name='event', + index=models.Index(models.F('start_time'), models.F('start_day'), models.F('end_day'), models.F('end_time'), django.db.models.functions.text.Lower('title'), name='datetimes title'), + ), + ] diff --git a/src/agenda_culturel/migrations/0129_batchimportation_agenda_cult_created_a23990_idx_and_more.py b/src/agenda_culturel/migrations/0129_batchimportation_agenda_cult_created_a23990_idx_and_more.py new file mode 100644 index 0000000..d88f1c2 --- /dev/null +++ b/src/agenda_culturel/migrations/0129_batchimportation_agenda_cult_created_a23990_idx_and_more.py @@ -0,0 +1,57 @@ +# Generated by Django 4.2.9 on 2024-12-11 19:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('agenda_culturel', '0128_event_datetimes_title'), + ] + + operations = [ + migrations.AddIndex( + model_name='batchimportation', + index=models.Index(fields=['created_date'], name='agenda_cult_created_a23990_idx'), + ), + migrations.AddIndex( + model_name='batchimportation', + index=models.Index(fields=['status'], name='agenda_cult_status_54b205_idx'), + ), + migrations.AddIndex( + model_name='batchimportation', + index=models.Index(fields=['created_date', 'recurrentImport'], name='agenda_cult_created_0296e4_idx'), + ), + migrations.AddIndex( + model_name='duplicatedevents', + index=models.Index(fields=['representative'], name='agenda_cult_represe_9a4fa2_idx'), + ), + migrations.AddIndex( + model_name='message', + index=models.Index(fields=['related_event'], name='agenda_cult_related_79de3c_idx'), + ), + migrations.AddIndex( + model_name='message', + index=models.Index(fields=['user'], name='agenda_cult_user_id_42dc88_idx'), + ), + migrations.AddIndex( + model_name='message', + index=models.Index(fields=['date'], name='agenda_cult_date_049c71_idx'), + ), + migrations.AddIndex( + model_name='message', + index=models.Index(fields=['spam', 'closed'], name='agenda_cult_spam_22f9b3_idx'), + ), + migrations.AddIndex( + model_name='place', + index=models.Index(fields=['name'], name='agenda_cult_name_222846_idx'), + ), + migrations.AddIndex( + model_name='place', + index=models.Index(fields=['city'], name='agenda_cult_city_156dc7_idx'), + ), + migrations.AddIndex( + model_name='place', + index=models.Index(fields=['location'], name='agenda_cult_locatio_6f3c05_idx'), + ), + ] diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index a01562f..2294c4b 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -21,6 +21,7 @@ from django.utils import timezone from django.contrib.postgres.search import TrigramSimilarity from django.db.models import Q, Count, F, Subquery, OuterRef, Func from django.db.models.functions import Lower +from django.contrib.postgres.lookups import Unaccent import recurrence.fields import recurrence import copy @@ -285,6 +286,10 @@ class DuplicatedEvents(models.Model): class Meta: verbose_name = _("Duplicated events") verbose_name_plural = _("Duplicated events") + indexes = [ + models.Index(fields=['representative']), + ] + def __init__(self, *args, **kwargs): self.events = None @@ -460,6 +465,11 @@ class Place(models.Model): verbose_name = _("Place") verbose_name_plural = _("Places") ordering = ["name"] + indexes = [ + models.Index(fields=['name']), + models.Index(fields=['city']), + models.Index(fields=['location']), + ] def __str__(self): if self.address: @@ -748,15 +758,6 @@ class Event(models.Model): last = self.get_consolidated_end_day() return [first + timedelta(n) for n in range(int((last - first).days) + 1)] - def get_nb_events_same_dates(self, remove_same_dup=True): - first = self.start_day - last = self.get_consolidated_end_day() - ignore_dup = None - if remove_same_dup: - ignore_dup = self.other_versions - calendar = CalendarList(first, last, exact=True, ignore_dup=ignore_dup) - return [(len(d.events), d.date) for dstr, d in calendar.get_calendar_days().items()] - def is_single_day(self, intuitive=True): return self.start_day == self.get_consolidated_end_day(intuitive) @@ -803,7 +804,11 @@ class Event(models.Model): permissions = [("set_duplicated_event", "Can set an event as duplicated")] indexes = [ models.Index(fields=["start_day", "start_time"]), - models.Index("start_time", Lower("title"), name="start_time title") + models.Index(fields=["end_day", "end_time"]), + models.Index(fields=["status"]), + models.Index(fields=["recurrence_dtstart", "recurrence_dtend"]), + models.Index("start_time", Lower("title"), name="start_time title"), + models.Index("start_time", "start_day", "end_day", "end_time", Lower("title"), name="datetimes title") ] def sorted_tags(self): @@ -1630,13 +1635,12 @@ class Event(models.Model): def get_concurrent_events(self, remove_same_dup=True): day = self.current_date if hasattr(self, "current_date") else self.start_day - day_events = CalendarDay(self.start_day).get_events() + day_events = CalendarDay(day, qs = Event.objects.filter(status=Event.STATUS.PUBLISHED)).get_events() return [ e for e in day_events if e != self and self.is_concurrent_event(e, day) - and e.status == Event.STATUS.PUBLISHED and (e.other_versions is None or e.other_versions != self.other_versions) ] @@ -1745,6 +1749,14 @@ class Message(models.Model): class Meta: verbose_name = _("Message") verbose_name_plural = _("Messages") + indexes = [ + models.Index(fields=['related_event']), + models.Index(fields=['user']), + models.Index(fields=['date']), + models.Index(fields=['spam', 'closed']), + ] + + subject = models.CharField( verbose_name=_("Subject"), @@ -1961,6 +1973,11 @@ class BatchImportation(models.Model): verbose_name = _("Batch importation") verbose_name_plural = _("Batch importations") permissions = [("run_batchimportation", "Can run a batch importation")] + indexes = [ + models.Index(fields=['created_date']), + models.Index(fields=['status']), + models.Index(fields=['created_date', 'recurrentImport']), + ] created_date = models.DateTimeField(auto_now_add=True) diff --git a/src/agenda_culturel/templates/agenda_culturel/page-event.html b/src/agenda_culturel/templates/agenda_culturel/page-event.html index 2012c9f..04832c9 100644 --- a/src/agenda_culturel/templates/agenda_culturel/page-event.html +++ b/src/agenda_culturel/templates/agenda_culturel/page-event.html @@ -55,39 +55,7 @@ {% endif %} {% endwith %} -
- {% with event.get_nb_events_same_dates as nb_events_same_dates %} - {% with nb_events_same_dates|length as c_dates %} -
-

Voir aussi

- {% if c_dates != 1 %} -

- Retrouvez ci-dessous tous les événements - {% if event.is_single_day %} - à la même date - {% else %} - aux mêmes dates - {% endif %} - que l'événement affiché. -

- {% endif %} -
- - {% endwith %} - {% endwith %} -
+ {% if event.other_versions and not event.other_versions.fixed %} {% with poss_dup=event.get_other_versions|only_allowed:user.is_authenticated %} {% if poss_dup|length > 0 %} diff --git a/src/agenda_culturel/views.py b/src/agenda_culturel/views.py index 8ef955c..41eff61 100644 --- a/src/agenda_culturel/views.py +++ b/src/agenda_culturel/views.py @@ -472,6 +472,8 @@ class EventDeleteView( class EventDetailView(UserPassesTestMixin, DetailView): model = Event template_name = "agenda_culturel/page-event.html" + queryset = Event.objects.select_related("exact_location").select_related("category").select_related("other_versions").select_related("other_versions__representative") + def test_func(self): return (