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 #6436 from matrix-org/babolivier/fix-state-retrieval
Browse files Browse the repository at this point in the history
Discard retention policies when retrieving state
  • Loading branch information
babolivier committed Nov 29, 2019
2 parents 7baeea9 + 78ec11c commit 6d8576c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog.d/6436.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug where a room could become unusable with a low retention policy and a low activity.
2 changes: 1 addition & 1 deletion synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def get_state_events(
raise NotFoundError("Can't find event for token %s" % (at_token,))

visible_events = yield filter_events_for_client(
self.storage, user_id, last_events
self.storage, user_id, last_events, apply_retention_policies=False
)

event = last_events[0]
Expand Down
26 changes: 18 additions & 8 deletions synapse/visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@

@defer.inlineCallbacks
def filter_events_for_client(
storage: Storage, user_id, events, is_peeking=False, always_include_ids=frozenset()
storage: Storage,
user_id,
events,
is_peeking=False,
always_include_ids=frozenset(),
apply_retention_policies=True,
):
"""
Check which events a user is allowed to see
Expand All @@ -59,6 +64,10 @@ def filter_events_for_client(
events
always_include_ids (set(event_id)): set of event ids to specifically
include (unless sender is ignored)
apply_retention_policies (bool): Whether to filter out events that's older than
allowed by the room's retention policy. Useful when this function is called
to e.g. check whether a user should be allowed to see the state at a given
event rather than to know if it should send an event to a user's client(s).
Returns:
Deferred[list[synapse.events.EventBase]]
Expand Down Expand Up @@ -86,13 +95,14 @@ def filter_events_for_client(

erased_senders = yield storage.main.are_users_erased((e.sender for e in events))

room_ids = set(e.room_id for e in events)
retention_policies = {}
if apply_retention_policies:
room_ids = set(e.room_id for e in events)
retention_policies = {}

for room_id in room_ids:
retention_policies[room_id] = yield storage.main.get_retention_policy_for_room(
room_id
)
for room_id in room_ids:
retention_policies[
room_id
] = yield storage.main.get_retention_policy_for_room(room_id)

def allowed(event):
"""
Expand All @@ -113,7 +123,7 @@ def allowed(event):

# Don't try to apply the room's retention policy if the event is a state event, as
# MSC1763 states that retention is only considered for non-state events.
if not event.is_state():
if apply_retention_policies and not event.is_state():
retention_policy = retention_policies[event.room_id]
max_lifetime = retention_policy.get("max_lifetime")

Expand Down

0 comments on commit 6d8576c

Please sign in to comment.