mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
presence: Add realm/timestamp index to UserPresence.
It adds this index:
"zerver_userpresence_realm_id_timestamp_25f410da_idx" btree (realm_id, "timestamp")
We expect this index to provide a major performance improvement when
fetching presence data for the whole realm from the database on
servers like zulipchat.com hosting several realms.
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.28 on 2020-02-08 20:34
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('zerver', '0267_backfill_userpresence_realm_id'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='userpresence',
|
||||||
|
name='realm',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='zerver.Realm'),
|
||||||
|
),
|
||||||
|
migrations.AlterIndexTogether(
|
||||||
|
name='userpresence',
|
||||||
|
index_together=set([('realm', 'timestamp')]),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -2327,9 +2327,12 @@ class UserPresence(models.Model):
|
|||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ("user_profile", "client")
|
unique_together = ("user_profile", "client")
|
||||||
|
index_together = [
|
||||||
|
("realm", "timestamp")
|
||||||
|
]
|
||||||
|
|
||||||
user_profile = models.ForeignKey(UserProfile, on_delete=CASCADE) # type: UserProfile
|
user_profile = models.ForeignKey(UserProfile, on_delete=CASCADE) # type: UserProfile
|
||||||
realm = models.ForeignKey(Realm, null=True) # type: Optional[Realm]
|
realm = models.ForeignKey(Realm) # type: Realm
|
||||||
client = models.ForeignKey(Client, on_delete=CASCADE) # type: Client
|
client = models.ForeignKey(Client, on_delete=CASCADE) # type: Client
|
||||||
|
|
||||||
# The time we heard this update from the client.
|
# The time we heard this update from the client.
|
||||||
|
|||||||
Reference in New Issue
Block a user