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:
Steve Howell
2020-02-08 20:36:25 +00:00
committed by Tim Abbott
parent fcac3a4342
commit d68052b68d
2 changed files with 29 additions and 1 deletions

View File

@@ -2327,9 +2327,12 @@ class UserPresence(models.Model):
"""
class Meta:
unique_together = ("user_profile", "client")
index_together = [
("realm", "timestamp")
]
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
# The time we heard this update from the client.