Quelques optimisation BD

This commit is contained in:
Jean-Marie Favreau 2024-11-23 15:00:55 +01:00
parent 5a66caae55
commit 2da854545f
5 changed files with 92 additions and 0 deletions

View File

@ -238,6 +238,7 @@ class CalendarList:
| Q(recurrence_dtend__lt=startdatetime) | Q(recurrence_dtend__lt=startdatetime)
) )
) )
| (Q(start_day__lte=self.c_firstdate) & (Q(end_day__isnull=True) | Q(end_day__gte=self.c_firstdate)))
).filter( ).filter(
Q(other_versions__isnull=True) | Q(other_versions__isnull=True) |
Q(other_versions__representative=F('pk')) | Q(other_versions__representative=F('pk')) |

View File

@ -0,0 +1,17 @@
# Generated by Django 4.2.9 on 2024-11-23 09:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('agenda_culturel', '0115_alter_organisation_options_alter_event_organisers'),
]
operations = [
migrations.AddIndex(
model_name='event',
index=models.Index(fields=['start_day', 'start_time'], name='agenda_cult_start_d_68ab5f_idx'),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 4.2.9 on 2024-11-23 10:11
from django.db import migrations, models
import django.db.models.functions.text
class Migration(migrations.Migration):
dependencies = [
('agenda_culturel', '0116_event_agenda_cult_start_d_68ab5f_idx'),
]
operations = [
migrations.AddIndex(
model_name='event',
index=models.Index(models.F('start_time'), django.db.models.functions.text.Lower('title'), name='start_time title'),
),
]

View File

@ -0,0 +1,33 @@
# Generated by Django 4.2.9 on 2024-11-23 10:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('agenda_culturel', '0117_event_start_time_title'),
]
operations = [
migrations.AlterModelOptions(
name='tag',
options={'verbose_name': 'Étiquette', 'verbose_name_plural': 'Étiquettes'},
),
migrations.AddIndex(
model_name='category',
index=models.Index(fields=['name'], name='agenda_cult_name_28aa03_idx'),
),
migrations.AddIndex(
model_name='referencelocation',
index=models.Index(fields=['name'], name='agenda_cult_name_76f079_idx'),
),
migrations.AddIndex(
model_name='staticcontent',
index=models.Index(fields=['name'], name='agenda_cult_name_fe4995_idx'),
),
migrations.AddIndex(
model_name='tag',
index=models.Index(fields=['name'], name='agenda_cult_name_9c9c74_idx'),
),
]

View File

@ -18,6 +18,7 @@ from django.core.files import File
from django.utils import timezone from django.utils import timezone
from django.contrib.postgres.search import TrigramSimilarity from django.contrib.postgres.search import TrigramSimilarity
from django.db.models import Q, Count, F, Subquery, OuterRef, Func from django.db.models import Q, Count, F, Subquery, OuterRef, Func
from django.db.models.functions import Lower
import recurrence.fields import recurrence.fields
import recurrence import recurrence
import copy import copy
@ -68,6 +69,9 @@ class StaticContent(models.Model):
class Meta: class Meta:
verbose_name = _("Static content") verbose_name = _("Static content")
verbose_name_plural = _("Static contents") verbose_name_plural = _("Static contents")
indexes = [
models.Index(fields=['name']),
]
def __str__(self): def __str__(self):
return self.name return self.name
@ -169,6 +173,9 @@ class Category(models.Model):
class Meta: class Meta:
verbose_name = _("Category") verbose_name = _("Category")
verbose_name_plural = _("Categories") verbose_name_plural = _("Categories")
indexes = [
models.Index(fields=['name']),
]
class Tag(models.Model): class Tag(models.Model):
@ -203,6 +210,13 @@ class Tag(models.Model):
default=False, default=False,
) )
class Meta:
verbose_name = _("Étiquette")
verbose_name_plural = _("Étiquettes")
indexes = [
models.Index(fields=['name']),
]
def get_absolute_url(self): def get_absolute_url(self):
return reverse("view_tag", kwargs={"t": self.name}) return reverse("view_tag", kwargs={"t": self.name})
@ -394,11 +408,16 @@ class ReferenceLocation(models.Model):
class Meta: class Meta:
verbose_name = _("Reference location") verbose_name = _("Reference location")
verbose_name_plural = _("Reference locations") verbose_name_plural = _("Reference locations")
indexes = [
models.Index(fields=['name']),
]
def __str__(self): def __str__(self):
return self.name return self.name
class Place(models.Model): class Place(models.Model):
name = models.CharField(verbose_name=_("Name"), help_text=_("Name of the place")) name = models.CharField(verbose_name=_("Name"), help_text=_("Name of the place"))
address = models.CharField( address = models.CharField(
@ -735,6 +754,10 @@ class Event(models.Model):
verbose_name = _("Event") verbose_name = _("Event")
verbose_name_plural = _("Events") verbose_name_plural = _("Events")
permissions = [("set_duplicated_event", "Can set an event as duplicated")] 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")
]
def sorted_tags(self): def sorted_tags(self):
if self.tags is None: if self.tags is None: