On remplace prefetch_related par select_related là où c'est possible
This commit is contained in:
parent
ecc347219c
commit
5a66caae55
@ -242,7 +242,7 @@ class CalendarList:
|
|||||||
Q(other_versions__isnull=True) |
|
Q(other_versions__isnull=True) |
|
||||||
Q(other_versions__representative=F('pk')) |
|
Q(other_versions__representative=F('pk')) |
|
||||||
Q(other_versions__representative__isnull=True)
|
Q(other_versions__representative__isnull=True)
|
||||||
).order_by("start_time", "title__unaccent__lower").prefetch_related("exact_location").prefetch_related("category").prefetch_related("other_versions").prefetch_related("other_versions__representative")
|
).order_by("start_time", "title__unaccent__lower").select_related("exact_location").select_related("category").select_related("other_versions").select_related("other_versions__representative")
|
||||||
|
|
||||||
firstdate = datetime.fromordinal(self.c_firstdate.toordinal())
|
firstdate = datetime.fromordinal(self.c_firstdate.toordinal())
|
||||||
if firstdate.tzinfo is None or firstdate.tzinfo.utcoffset(firstdate) is None:
|
if firstdate.tzinfo is None or firstdate.tzinfo.utcoffset(firstdate) is None:
|
||||||
|
@ -1978,7 +1978,7 @@ class CategorisationRule(models.Model):
|
|||||||
def get_category_from_rules(event):
|
def get_category_from_rules(event):
|
||||||
cats = defaultdict(lambda: 0)
|
cats = defaultdict(lambda: 0)
|
||||||
if CategorisationRule.rules is None:
|
if CategorisationRule.rules is None:
|
||||||
CategorisationRule.rules = CategorisationRule.objects.all().prefetch_related("category").prefetch_related("place")
|
CategorisationRule.rules = CategorisationRule.objects.all().select_related("category").select_related("place")
|
||||||
|
|
||||||
for rule in CategorisationRule.rules:
|
for rule in CategorisationRule.rules:
|
||||||
if rule.match(event):
|
if rule.match(event):
|
||||||
|
@ -1492,7 +1492,7 @@ def set_duplicate(request, year, month, day, pk):
|
|||||||
@login_required(login_url="/accounts/login/")
|
@login_required(login_url="/accounts/login/")
|
||||||
@permission_required("agenda_culturel.view_categorisationrule")
|
@permission_required("agenda_culturel.view_categorisationrule")
|
||||||
def categorisation_rules(request):
|
def categorisation_rules(request):
|
||||||
paginator = Paginator(CategorisationRule.objects.all().order_by("pk").prefetch_related("category").prefetch_related("place"), 100)
|
paginator = Paginator(CategorisationRule.objects.all().order_by("pk").select_related("category").select_related("place"), 100)
|
||||||
page = request.GET.get("page")
|
page = request.GET.get("page")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -1584,7 +1584,7 @@ def apply_categorisation_rules(request):
|
|||||||
else:
|
else:
|
||||||
# first we check if events are not correctly categorised
|
# first we check if events are not correctly categorised
|
||||||
to_categorise = []
|
to_categorise = []
|
||||||
events = Event.objects.filter(start_day__gte=datetime.now()).exclude(category=Category.get_default_category_id()).exclude(category=None).prefetch_related("exact_location").prefetch_related("category")
|
events = Event.objects.filter(start_day__gte=datetime.now()).exclude(category=Category.get_default_category_id()).exclude(category=None).select_related("exact_location").select_related("category")
|
||||||
for e in events:
|
for e in events:
|
||||||
c = CategorisationRule.get_category_from_rules(e)
|
c = CategorisationRule.get_category_from_rules(e)
|
||||||
if c and c != e.category:
|
if c and c != e.category:
|
||||||
@ -1593,7 +1593,7 @@ def apply_categorisation_rules(request):
|
|||||||
# then we apply rules on events without category
|
# then we apply rules on events without category
|
||||||
nb = 0
|
nb = 0
|
||||||
to_save = []
|
to_save = []
|
||||||
events = Event.objects.filter(start_day__gte=datetime.now()).filter(Q(category=Category.get_default_category_id()) | Q(category=None)).prefetch_related("exact_location").prefetch_related("category")
|
events = Event.objects.filter(start_day__gte=datetime.now()).filter(Q(category=Category.get_default_category_id()) | Q(category=None)).select_related("exact_location").select_related("category")
|
||||||
for e in events:
|
for e in events:
|
||||||
success = CategorisationRule.apply_rules(e)
|
success = CategorisationRule.apply_rules(e)
|
||||||
if success:
|
if success:
|
||||||
|
Loading…
Reference in New Issue
Block a user