Skip to content

Commit

Permalink
Add missing indexes on forum_conversation models
Browse files Browse the repository at this point in the history
  • Loading branch information
ellmetha committed Dec 21, 2020
1 parent e2d1125 commit a628c8c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
21 changes: 19 additions & 2 deletions machina/apps/forum_conversation/abstract_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
ApprovedManager = get_class('forum_conversation.managers', 'ApprovedManager')


class AbstractTopic(DatedModel):
class AbstractTopic(models.Model):
""" Represents a forum topic. """

forum = models.ForeignKey(
Expand Down Expand Up @@ -77,7 +77,12 @@ class AbstractTopic(DatedModel):
)

# The date of the latest post.
last_post_on = models.DateTimeField(blank=True, null=True, verbose_name=_('Last post added on'))
last_post_on = models.DateTimeField(
blank=True,
null=True,
db_index=True,
verbose_name=_('Last post added on')
)

# The first post and the last post of the topic. The first post can be unnaproved. The last post
# must be approved.
Expand All @@ -96,12 +101,24 @@ class AbstractTopic(DatedModel):
verbose_name=_('Subscribers'),
)

created = models.DateTimeField(
auto_now_add=True,
db_index=True,
verbose_name=_('Creation date')
)
updated = models.DateTimeField(
auto_now=True,
db_index=True,
verbose_name=_('Update date')
)

objects = models.Manager()
approved_objects = ApprovedManager()

class Meta:
abstract = True
app_label = 'forum_conversation'
indexes = [models.Index(fields=['type', 'last_post_on']), ]
ordering = ['-type', '-last_post_on', ]
get_latest_by = 'last_post_on'
verbose_name = _('Topic')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 3.1.2 on 2020-12-20 22:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('forum_conversation', '0012_auto_20200423_1049'),
]

operations = [
migrations.AlterField(
model_name='topic',
name='created',
field=models.DateTimeField(auto_now_add=True, db_index=True, verbose_name='Creation date'),
),
migrations.AlterField(
model_name='topic',
name='last_post_on',
field=models.DateTimeField(blank=True, db_index=True, null=True, verbose_name='Last post added on'),
),
migrations.AlterField(
model_name='topic',
name='updated',
field=models.DateTimeField(auto_now=True, db_index=True, verbose_name='Update date'),
),
migrations.AddIndex(
model_name='topic',
index=models.Index(fields=['type', 'last_post_on'], name='forum_conve_type_cc96d0_idx'),
),
]

0 comments on commit a628c8c

Please sign in to comment.