Skip to content

Commit

Permalink
Fix #3587 : Index les relations generiques des modeles des notifs. (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
GerardPaligot authored and gustavi committed May 9, 2016
1 parent 7d74dc7 commit 25f5cac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------

Expand Down
24 changes: 24 additions & 0 deletions zds/notification/migrations/0008_auto_20160507_1504.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
4 changes: 2 additions & 2 deletions zds/notification/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 25f5cac

Please sign in to comment.