diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2020-10-06 16:31:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-06 16:31:31 +0100 |
commit | a02446113012920c92264f632832308588649ed8 (patch) | |
tree | f3a58e1ef74f8fa1bcf472c8875db04216b4d057 /synapse/events/third_party_rules.py | |
parent | Merge pull request #8467 from matrix-org/rav/fix_3pevent_rules (diff) | |
download | synapse-a02446113012920c92264f632832308588649ed8.tar.xz |
Additional tests for third-party event rules (#8468)
* Optimise and test state fetching for 3p event rules Getting all the events at once is much more efficient than getting them individually * Test that 3p event rules can modify events
Diffstat (limited to 'synapse/events/third_party_rules.py')
-rw-r--r-- | synapse/events/third_party_rules.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/synapse/events/third_party_rules.py b/synapse/events/third_party_rules.py index 1ca77519d5..e38b8e67fb 100644 --- a/synapse/events/third_party_rules.py +++ b/synapse/events/third_party_rules.py @@ -61,12 +61,14 @@ class ThirdPartyEventRules: prev_state_ids = await context.get_prev_state_ids() # Retrieve the state events from the database. - state_events = {} - for key, event_id in prev_state_ids.items(): - state_events[key] = await self.store.get_event(event_id, allow_none=True) + events = await self.store.get_events(prev_state_ids.values()) + state_events = {(ev.type, ev.state_key): ev for ev in events.values()} - ret = await self.third_party_rules.check_event_allowed(event, state_events) - return ret + # The module can modify the event slightly if it wants, but caution should be + # exercised, and it's likely to go very wrong if applied to events received over + # federation. + + return await self.third_party_rules.check_event_allowed(event, state_events) async def on_create_room( self, requester: Requester, config: dict, is_requester_admin: bool |