mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-02 20:59:12 +01:00
Merge pull request #1640 from matrix-org/kegan/sync-perf
Return early on /sync code paths if a '*' filter is used
This commit is contained in:
commit
0cf2a64974
2 changed files with 51 additions and 9 deletions
|
@ -202,6 +202,26 @@ class FilterCollection(object):
|
||||||
def filter_room_account_data(self, events):
|
def filter_room_account_data(self, events):
|
||||||
return self._room_account_data.filter(self._room_filter.filter(events))
|
return self._room_account_data.filter(self._room_filter.filter(events))
|
||||||
|
|
||||||
|
def blocks_all_presence(self):
|
||||||
|
return (
|
||||||
|
self._presence_filter.filters_all_types() or
|
||||||
|
self._presence_filter.filters_all_senders()
|
||||||
|
)
|
||||||
|
|
||||||
|
def blocks_all_room_ephemeral(self):
|
||||||
|
return (
|
||||||
|
self._room_ephemeral_filter.filters_all_types() or
|
||||||
|
self._room_ephemeral_filter.filters_all_senders() or
|
||||||
|
self._room_ephemeral_filter.filters_all_rooms()
|
||||||
|
)
|
||||||
|
|
||||||
|
def blocks_all_room_timeline(self):
|
||||||
|
return (
|
||||||
|
self._room_timeline_filter.filters_all_types() or
|
||||||
|
self._room_timeline_filter.filters_all_senders() or
|
||||||
|
self._room_timeline_filter.filters_all_rooms()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Filter(object):
|
class Filter(object):
|
||||||
def __init__(self, filter_json):
|
def __init__(self, filter_json):
|
||||||
|
@ -218,6 +238,15 @@ class Filter(object):
|
||||||
|
|
||||||
self.contains_url = self.filter_json.get("contains_url", None)
|
self.contains_url = self.filter_json.get("contains_url", None)
|
||||||
|
|
||||||
|
def filters_all_types(self):
|
||||||
|
return "*" in self.not_types
|
||||||
|
|
||||||
|
def filters_all_senders(self):
|
||||||
|
return "*" in self.not_senders
|
||||||
|
|
||||||
|
def filters_all_rooms(self):
|
||||||
|
return "*" in self.not_rooms
|
||||||
|
|
||||||
def check(self, event):
|
def check(self, event):
|
||||||
"""Checks whether the filter matches the given event.
|
"""Checks whether the filter matches the given event.
|
||||||
|
|
||||||
|
|
|
@ -277,6 +277,7 @@ class SyncHandler(object):
|
||||||
"""
|
"""
|
||||||
with Measure(self.clock, "load_filtered_recents"):
|
with Measure(self.clock, "load_filtered_recents"):
|
||||||
timeline_limit = sync_config.filter_collection.timeline_limit()
|
timeline_limit = sync_config.filter_collection.timeline_limit()
|
||||||
|
block_all_timeline = sync_config.filter_collection.blocks_all_room_timeline()
|
||||||
|
|
||||||
if recents is None or newly_joined_room or timeline_limit < len(recents):
|
if recents is None or newly_joined_room or timeline_limit < len(recents):
|
||||||
limited = True
|
limited = True
|
||||||
|
@ -293,7 +294,7 @@ class SyncHandler(object):
|
||||||
else:
|
else:
|
||||||
recents = []
|
recents = []
|
||||||
|
|
||||||
if not limited:
|
if not limited or block_all_timeline:
|
||||||
defer.returnValue(TimelineBatch(
|
defer.returnValue(TimelineBatch(
|
||||||
events=recents,
|
events=recents,
|
||||||
prev_batch=now_token,
|
prev_batch=now_token,
|
||||||
|
@ -531,6 +532,11 @@ class SyncHandler(object):
|
||||||
)
|
)
|
||||||
newly_joined_rooms, newly_joined_users = res
|
newly_joined_rooms, newly_joined_users = res
|
||||||
|
|
||||||
|
block_all_presence_data = (
|
||||||
|
since_token is None and
|
||||||
|
sync_config.filter_collection.blocks_all_presence()
|
||||||
|
)
|
||||||
|
if not block_all_presence_data:
|
||||||
yield self._generate_sync_entry_for_presence(
|
yield self._generate_sync_entry_for_presence(
|
||||||
sync_result_builder, newly_joined_rooms, newly_joined_users
|
sync_result_builder, newly_joined_rooms, newly_joined_users
|
||||||
)
|
)
|
||||||
|
@ -709,7 +715,14 @@ class SyncHandler(object):
|
||||||
`(newly_joined_rooms, newly_joined_users)`
|
`(newly_joined_rooms, newly_joined_users)`
|
||||||
"""
|
"""
|
||||||
user_id = sync_result_builder.sync_config.user.to_string()
|
user_id = sync_result_builder.sync_config.user.to_string()
|
||||||
|
block_all_room_ephemeral = (
|
||||||
|
sync_result_builder.since_token is None and
|
||||||
|
sync_result_builder.sync_config.filter_collection.blocks_all_room_ephemeral()
|
||||||
|
)
|
||||||
|
|
||||||
|
if block_all_room_ephemeral:
|
||||||
|
ephemeral_by_room = {}
|
||||||
|
else:
|
||||||
now_token, ephemeral_by_room = yield self.ephemeral_by_room(
|
now_token, ephemeral_by_room = yield self.ephemeral_by_room(
|
||||||
sync_result_builder.sync_config,
|
sync_result_builder.sync_config,
|
||||||
now_token=sync_result_builder.now_token,
|
now_token=sync_result_builder.now_token,
|
||||||
|
|
Loading…
Reference in a new issue