mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
presence: Add realm_id to UserPresence.
This index is intended to optimize the performance of the very
frequently run query of "what is the presence status of all users in a
realm?".
Main changes:
- add realm_id to UserPresence
- add index for realm_id
- backfill realm_id for old rows
- change all writes to UserPresence to include
realm_id
The index is of this form:
"zerver_userpresence_realm_id_5c4ef5a9" btree (realm_id)
We will create an index on (realm_id, timestamp) in a
future commit, but I think it's a bit faster if you do
the backfill before the index.
There's also a minor tweak to the populate_db script.
This commit is contained in:
@@ -4063,11 +4063,18 @@ def do_update_user_presence(user_profile: UserProfile,
|
||||
log_time: datetime.datetime,
|
||||
status: int) -> None:
|
||||
client = consolidate_client(client)
|
||||
|
||||
defaults = dict(
|
||||
timestamp=log_time,
|
||||
status=status,
|
||||
realm_id=user_profile.realm_id
|
||||
)
|
||||
|
||||
(presence, created) = UserPresence.objects.get_or_create(
|
||||
user_profile = user_profile,
|
||||
client = client,
|
||||
defaults = {'timestamp': log_time,
|
||||
'status': status})
|
||||
defaults = defaults
|
||||
)
|
||||
|
||||
stale_status = (log_time - presence.timestamp) > datetime.timedelta(minutes=1, seconds=10)
|
||||
was_idle = presence.status == UserPresence.IDLE
|
||||
|
||||
Reference in New Issue
Block a user