Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #567 from matrix-org/erikj/sync_ephemeral
Browse files Browse the repository at this point in the history
Don't load all ephemeral state for a room on every sync
  • Loading branch information
erikjohnston committed Feb 9, 2016
2 parents 82631c5 + eff12e8 commit 7e3b586
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
20 changes: 6 additions & 14 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ def full_state_sync_for_joined_room(self, room_id, sync_config,
ephemeral_by_room=ephemeral_by_room,
tags_by_room=tags_by_room,
account_data_by_room=account_data_by_room,
all_ephemeral_by_room=ephemeral_by_room,
batch=batch,
full_state=True,
)
Expand Down Expand Up @@ -453,13 +452,6 @@ def incremental_sync_with_gap(self, sync_config, since_token):
)
now_token = now_token.copy_and_replace("presence_key", presence_key)

# We now fetch all ephemeral events for this room in order to get
# this users current read receipt. This could almost certainly be
# optimised.
_, all_ephemeral_by_room = yield self.ephemeral_by_room(
sync_config, now_token
)

now_token, ephemeral_by_room = yield self.ephemeral_by_room(
sync_config, now_token, since_token
)
Expand Down Expand Up @@ -591,7 +583,6 @@ def incremental_sync_with_gap(self, sync_config, since_token):
ephemeral_by_room=ephemeral_by_room,
tags_by_room=tags_by_room,
account_data_by_room=account_data_by_room,
all_ephemeral_by_room=all_ephemeral_by_room,
batch=batch,
full_state=full_state,
)
Expand Down Expand Up @@ -691,7 +682,6 @@ def incremental_sync_with_gap_for_room(self, room_id, sync_config,
since_token, now_token,
ephemeral_by_room, tags_by_room,
account_data_by_room,
all_ephemeral_by_room,
batch, full_state=False):
state = yield self.compute_state_delta(
room_id, batch, sync_config, since_token, now_token,
Expand Down Expand Up @@ -722,7 +712,7 @@ def incremental_sync_with_gap_for_room(self, room_id, sync_config,

if room_sync:
notifs = yield self.unread_notifs_for_room_id(
room_id, sync_config, all_ephemeral_by_room
room_id, sync_config
)

if notifs is not None:
Expand Down Expand Up @@ -906,10 +896,12 @@ def check_joined_room(self, sync_config, state_delta):
return False

@defer.inlineCallbacks
def unread_notifs_for_room_id(self, room_id, sync_config, ephemeral_by_room):
def unread_notifs_for_room_id(self, room_id, sync_config):
with Measure(self.clock, "unread_notifs_for_room_id"):
last_unread_event_id = self.last_read_event_id_for_room_and_user(
room_id, sync_config.user.to_string(), ephemeral_by_room
last_unread_event_id = yield self.store.get_last_receipt_event_id_for_user(
user_id=sync_config.user.to_string(),
room_id=room_id,
receipt_type="m.read"
)

notifs = []
Expand Down
14 changes: 14 additions & 0 deletions synapse/storage/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ def get_receipts_for_room(self, room_id, receipt_type):
desc="get_receipts_for_room",
)

@cached(num_args=3)
def get_last_receipt_event_id_for_user(self, user_id, room_id, receipt_type):
return self._simple_select_one_onecol(
table="receipts_linearized",
keyvalues={
"room_id": room_id,
"receipt_type": receipt_type,
"user_id": user_id
},
retcol="event_id",
desc="get_own_receipt_for_user",
allow_none=True,
)

@cachedInlineCallbacks(num_args=2)
def get_receipts_for_user(self, user_id, receipt_type):
def f(txn):
Expand Down

0 comments on commit 7e3b586

Please sign in to comment.