mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-09-26 15:50:50 -04:00
Improve /sync performance of when passing filters with empty arrays. (#14786)
This has two related changes: * It enables fast-path processing for an empty filter (`[]`) which was previously only used for wildcard not-filters (`["*"]`). * It special cases a `/sync` filter with no-rooms to skip all room processing, previously we would partially skip processing, but would generally still calculate intermediate values for each room which were then unused. Future changes might consider further optimizations: * Skip calculating per-room account data when all rooms are filtered (currently this is thrown away). * Make similar improvements to other endpoints which support filters.
This commit is contained in:
parent
5e0888076f
commit
7e582a25f8
4 changed files with 21 additions and 9 deletions
|
@ -283,6 +283,9 @@ class FilterCollection:
|
|||
await self._room_filter.filter(events)
|
||||
)
|
||||
|
||||
def blocks_all_rooms(self) -> bool:
|
||||
return self._room_filter.filters_all_rooms()
|
||||
|
||||
def blocks_all_presence(self) -> bool:
|
||||
return (
|
||||
self._presence_filter.filters_all_types()
|
||||
|
@ -351,13 +354,13 @@ class Filter:
|
|||
self.not_rel_types = filter_json.get("org.matrix.msc3874.not_rel_types", [])
|
||||
|
||||
def filters_all_types(self) -> bool:
|
||||
return "*" in self.not_types
|
||||
return self.types == [] or "*" in self.not_types
|
||||
|
||||
def filters_all_senders(self) -> bool:
|
||||
return "*" in self.not_senders
|
||||
return self.senders == [] or "*" in self.not_senders
|
||||
|
||||
def filters_all_rooms(self) -> bool:
|
||||
return "*" in self.not_rooms
|
||||
return self.rooms == [] or "*" in self.not_rooms
|
||||
|
||||
def _check(self, event: FilterEvent) -> bool:
|
||||
"""Checks whether the filter matches the given event.
|
||||
|
@ -450,8 +453,8 @@ class Filter:
|
|||
if any(map(match_func, disallowed_values)):
|
||||
return False
|
||||
|
||||
# Other the event does not match at least one of the allowed values,
|
||||
# reject it.
|
||||
# Otherwise if the event does not match at least one of the allowed
|
||||
# values, reject it.
|
||||
allowed_values = getattr(self, name)
|
||||
if allowed_values is not None:
|
||||
if not any(map(match_func, allowed_values)):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue