From 25f5cac7e6c7307de7e0576153b88ab28f478887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rard=20Paligot?= Date: Mon, 9 May 2016 11:44:11 +0200 Subject: [PATCH] Fix #3587 : Index les relations generiques des modeles des notifs. (#3594) * fix(notif): Index les relations generiques des modeles des notifs. Pour information, Django n'index pas automatiquement les relations generiques ce qui vient plomber les performances quand on commence a disposer d'une grosse base de donnees. Voir https://groups.google.com/forum/#!topic/django-users/GJ-FVh40-F4 Closes #3587 * [ci skip] Ajoute la commande d'opti mysql dans le update.md --- update.md | 2 ++ .../migrations/0008_auto_20160507_1504.py | 24 +++++++++++++++++++ zds/notification/models.py | 4 ++-- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 zds/notification/migrations/0008_auto_20160507_1504.py diff --git a/update.md b/update.md index 064d53f212..e3d0166a45 100644 --- a/update.md +++ b/update.md @@ -512,6 +512,8 @@ Notifications 1. Lors de l'application des migrations `python manage.py migrate`, Django va vous demander s'il doit supprimer la table topicfollowed. Renseignez oui. 2. Exécuter la commande `python manage.py migrate_subscriptions` pour migrer les anciennes notifications vers les nouvelles. +Si vous constatez des problèmes de performance, lancez la commande suivante : `mysqloptimize -uroot -p zdsdb` + Liste des tags exclus --------------------- diff --git a/zds/notification/migrations/0008_auto_20160507_1504.py b/zds/notification/migrations/0008_auto_20160507_1504.py new file mode 100644 index 0000000000..192322aa4b --- /dev/null +++ b/zds/notification/migrations/0008_auto_20160507_1504.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('notification', '0007_auto_20160121_2343'), + ] + + operations = [ + migrations.AlterField( + model_name='notification', + name='object_id', + field=models.PositiveIntegerField(db_index=True), + ), + migrations.AlterField( + model_name='subscription', + name='object_id', + field=models.PositiveIntegerField(db_index=True), + ), + ] diff --git a/zds/notification/models.py b/zds/notification/models.py index 381f50faa7..5cf2d8ed1f 100644 --- a/zds/notification/models.py +++ b/zds/notification/models.py @@ -30,7 +30,7 @@ class Meta: is_active = models.BooleanField(_(u'Actif'), default=True, db_index=True) by_email = models.BooleanField(_(u'Recevoir un email'), default=False) content_type = models.ForeignKey(ContentType) - object_id = models.PositiveIntegerField() + object_id = models.PositiveIntegerField(db_index=True) content_object = GenericForeignKey('content_type', 'object_id') last_notification = models.ForeignKey(u'Notification', related_name="last_notification", null=True, default=None) @@ -267,7 +267,7 @@ class Meta: subscription = models.ForeignKey(Subscription, related_name='subscription', db_index=True) pubdate = models.DateTimeField(_(u'Date de création'), auto_now_add=True, db_index=True) content_type = models.ForeignKey(ContentType) - object_id = models.PositiveIntegerField() + object_id = models.PositiveIntegerField(db_index=True) content_object = GenericForeignKey('content_type', 'object_id') is_read = models.BooleanField(_(u'Lue'), default=False, db_index=True) url = models.CharField('URL', max_length=255)