summary refs log tree commit diff
path: root/synapse/storage/databases
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/storage/databases')
-rw-r--r--synapse/storage/databases/__init__.py1
-rw-r--r--synapse/storage/databases/main/__init__.py2
-rw-r--r--synapse/storage/databases/main/account_data.py1
-rw-r--r--synapse/storage/databases/main/appservice.py1
-rw-r--r--synapse/storage/databases/main/cache.py1
-rw-r--r--synapse/storage/databases/main/censor_events.py1
-rw-r--r--synapse/storage/databases/main/client_ips.py1
-rw-r--r--synapse/storage/databases/main/deviceinbox.py2
-rw-r--r--synapse/storage/databases/main/devices.py2
-rw-r--r--synapse/storage/databases/main/directory.py1
-rw-r--r--synapse/storage/databases/main/e2e_room_keys.py1
-rw-r--r--synapse/storage/databases/main/end_to_end_keys.py2
-rw-r--r--synapse/storage/databases/main/event_federation.py154
-rw-r--r--synapse/storage/databases/main/event_push_actions.py1
-rw-r--r--synapse/storage/databases/main/events.py2
-rw-r--r--synapse/storage/databases/main/events_bg_updates.py1
-rw-r--r--synapse/storage/databases/main/events_forward_extremities.py1
-rw-r--r--synapse/storage/databases/main/experimental_features.py1
-rw-r--r--synapse/storage/databases/main/filtering.py2
-rw-r--r--synapse/storage/databases/main/keys.py1
-rw-r--r--synapse/storage/databases/main/lock.py1
-rw-r--r--synapse/storage/databases/main/media_repository.py2
-rw-r--r--synapse/storage/databases/main/metrics.py1
-rw-r--r--synapse/storage/databases/main/openid.py1
-rw-r--r--synapse/storage/databases/main/presence.py1
-rw-r--r--synapse/storage/databases/main/profile.py1
-rw-r--r--synapse/storage/databases/main/purge_events.py1
-rw-r--r--synapse/storage/databases/main/push_rule.py1
-rw-r--r--synapse/storage/databases/main/pusher.py1
-rw-r--r--synapse/storage/databases/main/receipts.py1
-rw-r--r--synapse/storage/databases/main/registration.py2
-rw-r--r--synapse/storage/databases/main/rejections.py1
-rw-r--r--synapse/storage/databases/main/room.py2
-rw-r--r--synapse/storage/databases/main/roommember.py1
-rw-r--r--synapse/storage/databases/main/search.py1
-rw-r--r--synapse/storage/databases/main/session.py1
-rw-r--r--synapse/storage/databases/main/signatures.py1
-rw-r--r--synapse/storage/databases/main/state.py2
-rw-r--r--synapse/storage/databases/main/state_deltas.py1
-rw-r--r--synapse/storage/databases/main/stats.py1
-rw-r--r--synapse/storage/databases/main/stream.py26
-rw-r--r--synapse/storage/databases/main/tags.py2
-rw-r--r--synapse/storage/databases/main/task_scheduler.py1
-rw-r--r--synapse/storage/databases/main/transactions.py1
-rw-r--r--synapse/storage/databases/main/ui_auth.py1
-rw-r--r--synapse/storage/databases/main/user_directory.py1
-rw-r--r--synapse/storage/databases/state/__init__.py1
-rw-r--r--synapse/storage/databases/state/bg_updates.py1
-rw-r--r--synapse/storage/databases/state/store.py1
49 files changed, 206 insertions, 32 deletions
diff --git a/synapse/storage/databases/__init__.py b/synapse/storage/databases/__init__.py

index 3a8766f746..dd9fc01fb0 100644 --- a/synapse/storage/databases/__init__.py +++ b/synapse/storage/databases/__init__.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019 The Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/__init__.py b/synapse/storage/databases/main/__init__.py
index 5551211ffd..394985d87f 100644 --- a/synapse/storage/databases/main/__init__.py +++ b/synapse/storage/databases/main/__init__.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019-2021 The Matrix.org Foundation C.I.C. +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/account_data.py b/synapse/storage/databases/main/account_data.py
index 933ff5d5be..563450a97e 100644 --- a/synapse/storage/databases/main/account_data.py +++ b/synapse/storage/databases/main/account_data.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/appservice.py b/synapse/storage/databases/main/appservice.py
index 1e1611f2d1..766c94fc14 100644 --- a/synapse/storage/databases/main/appservice.py +++ b/synapse/storage/databases/main/appservice.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2015, 2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/cache.py b/synapse/storage/databases/main/cache.py
index 6070e96792..7314d87404 100644 --- a/synapse/storage/databases/main/cache.py +++ b/synapse/storage/databases/main/cache.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019 The Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/censor_events.py b/synapse/storage/databases/main/censor_events.py
index 0637153a60..5b15fd707d 100644 --- a/synapse/storage/databases/main/censor_events.py +++ b/synapse/storage/databases/main/censor_events.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2020 The Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/client_ips.py b/synapse/storage/databases/main/client_ips.py
index 957b0cd066..628c3576b7 100644 --- a/synapse/storage/databases/main/client_ips.py +++ b/synapse/storage/databases/main/client_ips.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/deviceinbox.py b/synapse/storage/databases/main/deviceinbox.py
index 5a1a3e8e65..008b925fb2 100644 --- a/synapse/storage/databases/main/deviceinbox.py +++ b/synapse/storage/databases/main/deviceinbox.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2021 The Matrix.org Foundation C.I.C. +# Copyright 2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/devices.py b/synapse/storage/databases/main/devices.py
index d3859014b6..881714d4fa 100644 --- a/synapse/storage/databases/main/devices.py +++ b/synapse/storage/databases/main/devices.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019,2020 The Matrix.org Foundation C.I.C. +# Copyright 2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/directory.py b/synapse/storage/databases/main/directory.py
index efb3086a2a..49c0575aca 100644 --- a/synapse/storage/databases/main/directory.py +++ b/synapse/storage/databases/main/directory.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/e2e_room_keys.py b/synapse/storage/databases/main/e2e_room_keys.py
index ac1d37cac1..4d6a921ab2 100644 --- a/synapse/storage/databases/main/e2e_room_keys.py +++ b/synapse/storage/databases/main/e2e_room_keys.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019 Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/end_to_end_keys.py b/synapse/storage/databases/main/end_to_end_keys.py
index 96ec140bf4..c96371a0d3 100644 --- a/synapse/storage/databases/main/end_to_end_keys.py +++ b/synapse/storage/databases/main/end_to_end_keys.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019,2020 The Matrix.org Foundation C.I.C. +# Copyright 2015, 2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/event_federation.py b/synapse/storage/databases/main/event_federation.py
index ddc2baf95d..12e882062a 100644 --- a/synapse/storage/databases/main/event_federation.py +++ b/synapse/storage/databases/main/event_federation.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify @@ -159,6 +160,13 @@ class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBas unique_columns=("event_id", "room_id"), ) + self.db_pool.updates.register_background_index_update( + update_name="event_auth_chain_links_origin_index", + index_name="event_auth_chain_links_origin_index", + table="event_auth_chain_links", + columns=("origin_chain_id", "origin_sequence_number"), + ) + async def get_auth_chain( self, room_id: str, event_ids: Collection[str], include_given: bool = False ) -> List[EventBase]: @@ -271,38 +279,63 @@ class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBas # Now we look up all links for the chains we have, adding chains that # are reachable from any event. + # + # This query is structured to first get all chain IDs reachable, and + # then pull out all links from those chains. This does pull out more + # rows than is strictly necessary, however there isn't a way of + # structuring the recursive part of query to pull out the links without + # also returning large quantities of redundant data (which can make it a + # lot slower). sql = """ + WITH RECURSIVE links(chain_id) AS ( + SELECT + DISTINCT origin_chain_id + FROM event_auth_chain_links WHERE %s + UNION + SELECT + target_chain_id + FROM event_auth_chain_links + INNER JOIN links ON (chain_id = origin_chain_id) + ) SELECT origin_chain_id, origin_sequence_number, target_chain_id, target_sequence_number - FROM event_auth_chain_links - WHERE %s + FROM links + INNER JOIN event_auth_chain_links ON (chain_id = origin_chain_id) """ # A map from chain ID to max sequence number *reachable* from any event ID. chains: Dict[int, int] = {} # Add all linked chains reachable from initial set of chains. - for batch2 in batch_iter(event_chains, 1000): + chains_to_fetch = set(event_chains.keys()) + while chains_to_fetch: + batch2 = tuple(itertools.islice(chains_to_fetch, 100)) + chains_to_fetch.difference_update(batch2) clause, args = make_in_list_sql_clause( txn.database_engine, "origin_chain_id", batch2 ) txn.execute(sql % (clause,), args) + links: Dict[int, List[Tuple[int, int, int]]] = {} + for ( origin_chain_id, origin_sequence_number, target_chain_id, target_sequence_number, ) in txn: - # chains are only reachable if the origin sequence number of - # the link is less than the max sequence number in the - # origin chain. - if origin_sequence_number <= event_chains.get(origin_chain_id, 0): - chains[target_chain_id] = max( - target_sequence_number, - chains.get(target_chain_id, 0), - ) + links.setdefault(origin_chain_id, []).append( + (origin_sequence_number, target_chain_id, target_sequence_number) + ) + + for chain_id in links: + if chain_id not in event_chains: + continue + + _materialize(chain_id, event_chains[chain_id], links, chains) + + chains_to_fetch.difference_update(chains) # Add the initial set of chains, excluding the sequence corresponding to # initial event. @@ -529,41 +562,64 @@ class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBas chains[chain_id] = max(seq_no, chains.get(chain_id, 0)) - # Now we look up all links for the chains we have, adding chains to - # set_to_chain that are reachable from each set. + # Now we look up all links for the chains we have, adding chains that + # are reachable from any event. + # + # This query is structured to first get all chain IDs reachable, and + # then pull out all links from those chains. This does pull out more + # rows than is strictly necessary, however there isn't a way of + # structuring the recursive part of query to pull out the links without + # also returning large quantities of redundant data (which can make it a + # lot slower). sql = """ + WITH RECURSIVE links(chain_id) AS ( + SELECT + DISTINCT origin_chain_id + FROM event_auth_chain_links WHERE %s + UNION + SELECT + target_chain_id + FROM event_auth_chain_links + INNER JOIN links ON (chain_id = origin_chain_id) + ) SELECT origin_chain_id, origin_sequence_number, target_chain_id, target_sequence_number - FROM event_auth_chain_links - WHERE %s + FROM links + INNER JOIN event_auth_chain_links ON (chain_id = origin_chain_id) """ # (We need to take a copy of `seen_chains` as we want to mutate it in # the loop) - for batch2 in batch_iter(set(seen_chains), 1000): + chains_to_fetch = set(seen_chains) + while chains_to_fetch: + batch2 = tuple(itertools.islice(chains_to_fetch, 100)) clause, args = make_in_list_sql_clause( txn.database_engine, "origin_chain_id", batch2 ) txn.execute(sql % (clause,), args) + links: Dict[int, List[Tuple[int, int, int]]] = {} + for ( origin_chain_id, origin_sequence_number, target_chain_id, target_sequence_number, ) in txn: - for chains in set_to_chain: - # chains are only reachable if the origin sequence number of - # the link is less than the max sequence number in the - # origin chain. - if origin_sequence_number <= chains.get(origin_chain_id, 0): - chains[target_chain_id] = max( - target_sequence_number, - chains.get(target_chain_id, 0), - ) + links.setdefault(origin_chain_id, []).append( + (origin_sequence_number, target_chain_id, target_sequence_number) + ) + + for chains in set_to_chain: + for chain_id in links: + if chain_id not in chains: + continue - seen_chains.add(target_chain_id) + _materialize(chain_id, chains[chain_id], links, chains) + + chains_to_fetch.difference_update(chains) + seen_chains.update(chains) # Now for each chain we figure out the maximum sequence number reachable # from *any* state set and the minimum sequence number reachable from @@ -2103,3 +2159,49 @@ class EventFederationStore(EventFederationWorkerStore): ) return batch_size + + +def _materialize( + origin_chain_id: int, + origin_sequence_number: int, + links: Dict[int, List[Tuple[int, int, int]]], + materialized: Dict[int, int], +) -> None: + """Helper function for fetching auth chain links. For a given origin chain + ID / sequence number and a dictionary of links, updates the materialized + dict with the reachable chains. + + To get a dict of all chains reachable from a set of chains this function can + be called in a loop, once per origin chain with the same links and + materialized args. The materialized dict will the result. + + Args: + origin_chain_id, origin_sequence_number + links: map of the links between chains as a dict from origin chain ID + to list of 3-tuples of origin sequence number, target chain ID and + target sequence number. + materialized: dict to update with new reachability information, as a + map from chain ID to max sequence number reachable. + """ + + # Do a standard graph traversal. + stack = [(origin_chain_id, origin_sequence_number)] + + while stack: + c, s = stack.pop() + + chain_links = links.get(c, []) + for ( + sequence_number, + target_chain_id, + target_sequence_number, + ) in chain_links: + # Ignore any links that are higher up the chain + if sequence_number > s: + continue + + # Check if we have already visited the target chain before, if so we + # can skip it. + if materialized.get(target_chain_id, 0) < target_sequence_number: + stack.append((target_chain_id, target_sequence_number)) + materialized[target_chain_id] = target_sequence_number diff --git a/synapse/storage/databases/main/event_push_actions.py b/synapse/storage/databases/main/event_push_actions.py
index 6d4e2942ea..d7aa8a0ee0 100644 --- a/synapse/storage/databases/main/event_push_actions.py +++ b/synapse/storage/databases/main/event_push_actions.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2015 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/events.py b/synapse/storage/databases/main/events.py
index acdf582d09..d5942a10b2 100644 --- a/synapse/storage/databases/main/events.py +++ b/synapse/storage/databases/main/events.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019-2021 The Matrix.org Foundation C.I.C. +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/events_bg_updates.py b/synapse/storage/databases/main/events_bg_updates.py
index 16311b6d1b..6c979f9f2c 100644 --- a/synapse/storage/databases/main/events_bg_updates.py +++ b/synapse/storage/databases/main/events_bg_updates.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019-2022 The Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/events_forward_extremities.py b/synapse/storage/databases/main/events_forward_extremities.py
index 4343b41bbd..bd763885d7 100644 --- a/synapse/storage/databases/main/events_forward_extremities.py +++ b/synapse/storage/databases/main/events_forward_extremities.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2021 The Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/experimental_features.py b/synapse/storage/databases/main/experimental_features.py
index 2e2b8038af..fbb98d8f63 100644 --- a/synapse/storage/databases/main/experimental_features.py +++ b/synapse/storage/databases/main/experimental_features.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2023 The Matrix.org Foundation C.I.C # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/filtering.py b/synapse/storage/databases/main/filtering.py
index 9211d91a97..af9634bad4 100644 --- a/synapse/storage/databases/main/filtering.py +++ b/synapse/storage/databases/main/filtering.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2021 The Matrix.org Foundation C.I.C. +# Copyright 2015, 2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/keys.py b/synapse/storage/databases/main/keys.py
index 974e303149..2a99a97dd6 100644 --- a/synapse/storage/databases/main/keys.py +++ b/synapse/storage/databases/main/keys.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/lock.py b/synapse/storage/databases/main/lock.py
index 749b149eaf..0794cc6d25 100644 --- a/synapse/storage/databases/main/lock.py +++ b/synapse/storage/databases/main/lock.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2021 Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/media_repository.py b/synapse/storage/databases/main/media_repository.py
index 81051a0853..b5ed1bf9c8 100644 --- a/synapse/storage/databases/main/media_repository.py +++ b/synapse/storage/databases/main/media_repository.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2020-2021 The Matrix.org Foundation C.I.C. +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/metrics.py b/synapse/storage/databases/main/metrics.py
index d675f2face..9ce1100b5c 100644 --- a/synapse/storage/databases/main/metrics.py +++ b/synapse/storage/databases/main/metrics.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2020 The Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/openid.py b/synapse/storage/databases/main/openid.py
index 1f9b0b39bf..0db7f73730 100644 --- a/synapse/storage/databases/main/openid.py +++ b/synapse/storage/databases/main/openid.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019-2021 The Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/presence.py b/synapse/storage/databases/main/presence.py
index f95ae0d417..567c2d30bd 100644 --- a/synapse/storage/databases/main/presence.py +++ b/synapse/storage/databases/main/presence.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/profile.py b/synapse/storage/databases/main/profile.py
index 2a8d2c8e70..996aea808d 100644 --- a/synapse/storage/databases/main/profile.py +++ b/synapse/storage/databases/main/profile.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/purge_events.py b/synapse/storage/databases/main/purge_events.py
index 6143d64352..3b81ed943c 100644 --- a/synapse/storage/databases/main/purge_events.py +++ b/synapse/storage/databases/main/purge_events.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2020 The Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/push_rule.py b/synapse/storage/databases/main/push_rule.py
index 0060fdc72f..91beca6ffc 100644 --- a/synapse/storage/databases/main/push_rule.py +++ b/synapse/storage/databases/main/push_rule.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/pusher.py b/synapse/storage/databases/main/pusher.py
index 8705e5818b..39e22d3b43 100644 --- a/synapse/storage/databases/main/pusher.py +++ b/synapse/storage/databases/main/pusher.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/receipts.py b/synapse/storage/databases/main/receipts.py
index 8dfad4bc9d..3c7708f5f3 100644 --- a/synapse/storage/databases/main/receipts.py +++ b/synapse/storage/databases/main/receipts.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/registration.py b/synapse/storage/databases/main/registration.py
index bea0f56a21..d939ade427 100644 --- a/synapse/storage/databases/main/registration.py +++ b/synapse/storage/databases/main/registration.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019,2020 The Matrix.org Foundation C.I.C. +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/rejections.py b/synapse/storage/databases/main/rejections.py
index c4ce668f31..a603258644 100644 --- a/synapse/storage/databases/main/rejections.py +++ b/synapse/storage/databases/main/rejections.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/room.py b/synapse/storage/databases/main/room.py
index f6448d0818..81c7bf3712 100644 --- a/synapse/storage/databases/main/room.py +++ b/synapse/storage/databases/main/room.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019, 2022 The Matrix.org Foundation C.I.C. +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py
index e1ac93415c..5b0daffa46 100644 --- a/synapse/storage/databases/main/roommember.py +++ b/synapse/storage/databases/main/roommember.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/search.py b/synapse/storage/databases/main/search.py
index ad0aea2ecb..4a0afb50ac 100644 --- a/synapse/storage/databases/main/search.py +++ b/synapse/storage/databases/main/search.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2015, 2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/session.py b/synapse/storage/databases/main/session.py
index 18a95e443d..8a1331d4c8 100644 --- a/synapse/storage/databases/main/session.py +++ b/synapse/storage/databases/main/session.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2021 The Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/signatures.py b/synapse/storage/databases/main/signatures.py
index 8fcc361fd7..ef86151e31 100644 --- a/synapse/storage/databases/main/signatures.py +++ b/synapse/storage/databases/main/signatures.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/state.py b/synapse/storage/databases/main/state.py
index 8006046453..3220d515d9 100644 --- a/synapse/storage/databases/main/state.py +++ b/synapse/storage/databases/main/state.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2020 The Matrix.org Foundation C.I.C. +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/state_deltas.py b/synapse/storage/databases/main/state_deltas.py
index 5eb5217794..036972ac25 100644 --- a/synapse/storage/databases/main/state_deltas.py +++ b/synapse/storage/databases/main/state_deltas.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2018 Vector Creations Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/stats.py b/synapse/storage/databases/main/stats.py
index 98b467f490..e9f6a918c7 100644 --- a/synapse/storage/databases/main/stats.py +++ b/synapse/storage/databases/main/stats.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019 The Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/stream.py b/synapse/storage/databases/main/stream.py
index aeeb74b46d..19041cc35b 100644 --- a/synapse/storage/databases/main/stream.py +++ b/synapse/storage/databases/main/stream.py
@@ -1,6 +1,9 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019 The Matrix.org Foundation C.I.C. +# Copyright 2017 Vector Creations Ltd +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify @@ -398,14 +401,25 @@ def filter_to_clause(event_filter: Optional[Filter]) -> Tuple[str, List[str]]: clauses = [] args = [] + # Handle event types with potential wildcard characters if event_filter.types: - clauses.append( - "(%s)" % " OR ".join("event.type = ?" for _ in event_filter.types) - ) - args.extend(event_filter.types) - + type_clauses = [] + for typ in event_filter.types: + if "*" in typ: + type_clauses.append("event.type LIKE ?") + typ = typ.replace("*", "%") # Replace * with % for SQL LIKE pattern + else: + type_clauses.append("event.type = ?") + args.append(typ) + clauses.append("(%s)" % " OR ".join(type_clauses)) + + # Handle event types to exclude with potential wildcard characters for typ in event_filter.not_types: - clauses.append("event.type != ?") + if "*" in typ: + clauses.append("event.type NOT LIKE ?") + typ = typ.replace("*", "%") + else: + clauses.append("event.type != ?") args.append(typ) if event_filter.senders: diff --git a/synapse/storage/databases/main/tags.py b/synapse/storage/databases/main/tags.py
index 77736fcc6e..b5af294384 100644 --- a/synapse/storage/databases/main/tags.py +++ b/synapse/storage/databases/main/tags.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2021 The Matrix.org Foundation C.I.C. +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/task_scheduler.py b/synapse/storage/databases/main/task_scheduler.py
index 2d1daf642e..7b95616432 100644 --- a/synapse/storage/databases/main/task_scheduler.py +++ b/synapse/storage/databases/main/task_scheduler.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2023 The Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/transactions.py b/synapse/storage/databases/main/transactions.py
index bb38ed7a37..c91c44818f 100644 --- a/synapse/storage/databases/main/transactions.py +++ b/synapse/storage/databases/main/transactions.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/ui_auth.py b/synapse/storage/databases/main/ui_auth.py
index 66ead79594..17bd0ac09a 100644 --- a/synapse/storage/databases/main/ui_auth.py +++ b/synapse/storage/databases/main/ui_auth.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2020 Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/main/user_directory.py b/synapse/storage/databases/main/user_directory.py
index 106d04b53f..a1c4b8c6c3 100644 --- a/synapse/storage/databases/main/user_directory.py +++ b/synapse/storage/databases/main/user_directory.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2017 Vector Creations Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/state/__init__.py b/synapse/storage/databases/state/__init__.py
index 7af366bba1..ad94c9452a 100644 --- a/synapse/storage/databases/state/__init__.py +++ b/synapse/storage/databases/state/__init__.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019 The Matrix.org Foundation C.I.C. # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/state/bg_updates.py b/synapse/storage/databases/state/bg_updates.py
index e0dd4ba98a..ea7d8199a7 100644 --- a/synapse/storage/databases/state/bg_updates.py +++ b/synapse/storage/databases/state/bg_updates.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/databases/state/store.py b/synapse/storage/databases/state/store.py
index 0c1fa1866d..e64495ba8d 100644 --- a/synapse/storage/databases/state/store.py +++ b/synapse/storage/databases/state/store.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014-2016 OpenMarket Ltd # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify