diff options
author | Kegan Dougal <kegan@matrix.org> | 2016-11-22 16:38:35 +0000 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2016-11-22 16:38:35 +0000 |
commit | 83bcdcee616806ad4b39582b1015a37679b82b9a (patch) | |
tree | 1073d57fd509a730bf3bee82a90eeef873a65b51 /synapse/api | |
parent | Merge pull request #1638 from matrix-org/kegan/sync-event-fields (diff) | |
download | synapse-83bcdcee616806ad4b39582b1015a37679b82b9a.tar.xz |
Return early on /sync code paths if a '*' filter is used
This is currently very conservative in that it only does this if there is no `since` token. This limits the risk to clients likely to be doing one-off syncs (like bridges), but does mean that normal human clients won't benefit from the time savings here. If the savings are large enough, I would consider generalising this to just check the filter.
Diffstat (limited to 'synapse/api')
-rw-r--r-- | synapse/api/filtering.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/synapse/api/filtering.py b/synapse/api/filtering.py index 6f16e4d406..fb291d7fb9 100644 --- a/synapse/api/filtering.py +++ b/synapse/api/filtering.py @@ -202,6 +202,26 @@ class FilterCollection(object): def filter_room_account_data(self, 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): def __init__(self, filter_json): @@ -218,6 +238,15 @@ class Filter(object): 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): """Checks whether the filter matches the given event. |