make lazy_load_members configurable in filters

This commit is contained in:
Matthew Hodgson 2018-03-19 01:15:13 +00:00
parent 478af0f720
commit b2f2282947
2 changed files with 15 additions and 9 deletions

View File

@ -260,6 +260,9 @@ class FilterCollection(object):
def ephemeral_limit(self): def ephemeral_limit(self):
return self._room_ephemeral_filter.limit() return self._room_ephemeral_filter.limit()
def lazy_load_members(self):
return self._room_state_filter.lazy_load_members()
def filter_presence(self, events): def filter_presence(self, events):
return self._presence_filter.filter(events) return self._presence_filter.filter(events)
@ -416,6 +419,9 @@ class Filter(object):
def limit(self): def limit(self):
return self.filter_json.get("limit", 10) return self.filter_json.get("limit", 10)
def lazy_load_members(self):
return self.filter_json.get("lazy_load_members", False)
def _matches_wildcard(actual_value, filter_value): def _matches_wildcard(actual_value, filter_value):
if filter_value.endswith("*"): if filter_value.endswith("*"):

View File

@ -442,7 +442,7 @@ class SyncHandler(object):
@defer.inlineCallbacks @defer.inlineCallbacks
def compute_state_delta(self, room_id, batch, sync_config, since_token, now_token, def compute_state_delta(self, room_id, batch, sync_config, since_token, now_token,
full_state, filter_members): full_state):
""" Works out the differnce in state between the start of the timeline """ Works out the differnce in state between the start of the timeline
and the previous sync. and the previous sync.
@ -455,7 +455,7 @@ class SyncHandler(object):
be None. be None.
now_token(str): Token of the end of the current batch. now_token(str): Token of the end of the current batch.
full_state(bool): Whether to force returning the full state. full_state(bool): Whether to force returning the full state.
filter_members(bool): Whether to only return state for members lazy_load_members(bool): Whether to only return state for members
referenced in this timeline segment referenced in this timeline segment
Returns: Returns:
@ -470,8 +470,9 @@ class SyncHandler(object):
types = None types = None
member_state_ids = {} member_state_ids = {}
lazy_load_members = sync_config.filter_collection.lazy_load_members()
if filter_members: if lazy_load_members:
# We only request state for the members needed to display the # We only request state for the members needed to display the
# timeline: # timeline:
@ -490,7 +491,7 @@ class SyncHandler(object):
if not types: if not types:
# an optimisation to stop needlessly trying to calculate # an optimisation to stop needlessly trying to calculate
# member_state_ids # member_state_ids
filter_members = False lazy_load_members = False
types.append((None, None)) # don't just filter to room members types.append((None, None)) # don't just filter to room members
@ -511,7 +512,7 @@ class SyncHandler(object):
state_ids = current_state_ids state_ids = current_state_ids
if filter_members: if lazy_load_members:
member_state_ids = { member_state_ids = {
t: state_ids[t] t: state_ids[t]
for t in state_ids if t[0] == EventTypes.Member for t in state_ids if t[0] == EventTypes.Member
@ -542,7 +543,7 @@ class SyncHandler(object):
batch.events[0].event_id, types=types batch.events[0].event_id, types=types
) )
if filter_members: if lazy_load_members:
member_state_ids = { member_state_ids = {
t: state_at_timeline_start[t] t: state_at_timeline_start[t]
for t in state_at_timeline_start if t[0] == EventTypes.Member for t in state_at_timeline_start if t[0] == EventTypes.Member
@ -562,7 +563,7 @@ class SyncHandler(object):
) )
else: else:
state_ids = {} state_ids = {}
if filter_members: if lazy_load_members:
# TODO: filter out redundant members based on their mxids (not their # TODO: filter out redundant members based on their mxids (not their
# event_ids) at this point. We know we can do it based on mxid as this # event_ids) at this point. We know we can do it based on mxid as this
# is an non-gappy incremental sync. # is an non-gappy incremental sync.
@ -1380,8 +1381,7 @@ class SyncHandler(object):
return return
state = yield self.compute_state_delta( state = yield self.compute_state_delta(
room_id, batch, sync_config, since_token, now_token, room_id, batch, sync_config, since_token, now_token, full_state=full_state
full_state=full_state, filter_members=True
) )
if room_builder.rtype == "joined": if room_builder.rtype == "joined":