summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/__init__.py1
-rw-r--r--synapse/storage/_base.py2
-rw-r--r--synapse/storage/background_updates.py1
-rw-r--r--synapse/storage/controllers/__init__.py1
-rw-r--r--synapse/storage/controllers/persist_events.py2
-rw-r--r--synapse/storage/controllers/purge_events.py1
-rw-r--r--synapse/storage/controllers/state.py1
-rw-r--r--synapse/storage/controllers/stats.py1
-rw-r--r--synapse/storage/database.py2
-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
-rw-r--r--synapse/storage/engines/__init__.py1
-rw-r--r--synapse/storage/engines/_base.py1
-rw-r--r--synapse/storage/engines/postgres.py1
-rw-r--r--synapse/storage/engines/sqlite.py1
-rw-r--r--synapse/storage/keys.py1
-rw-r--r--synapse/storage/prepare_database.py1
-rw-r--r--synapse/storage/push_rule.py1
-rw-r--r--synapse/storage/roommember.py1
-rw-r--r--synapse/storage/schema/__init__.py3
-rw-r--r--synapse/storage/schema/main/delta/20/pushers.py1
-rw-r--r--synapse/storage/schema/main/delta/25/fts.py1
-rw-r--r--synapse/storage/schema/main/delta/27/ts.py1
-rw-r--r--synapse/storage/schema/main/delta/30/as_users.py1
-rw-r--r--synapse/storage/schema/main/delta/31/pushers_0.py1
-rw-r--r--synapse/storage/schema/main/delta/31/search_update.py1
-rw-r--r--synapse/storage/schema/main/delta/33/event_fields.py1
-rw-r--r--synapse/storage/schema/main/delta/33/remote_media_ts.py1
-rw-r--r--synapse/storage/schema/main/delta/34/cache_stream.py1
-rw-r--r--synapse/storage/schema/main/delta/34/received_txn_purge.py1
-rw-r--r--synapse/storage/schema/main/delta/37/remove_auth_idx.py1
-rw-r--r--synapse/storage/schema/main/delta/42/user_dir.py1
-rw-r--r--synapse/storage/schema/main/delta/58/06dlols_unique_idx.py1
-rw-r--r--synapse/storage/schema/main/delta/58/11user_id_seq.py1
-rw-r--r--synapse/storage/schema/main/delta/59/01ignored_user.py1
-rw-r--r--synapse/storage/schema/main/delta/61/03recreate_min_depth.py1
-rw-r--r--synapse/storage/schema/main/delta/68/05partial_state_rooms_triggers.py1
-rw-r--r--synapse/storage/schema/main/delta/69/01as_txn_seq.py1
-rw-r--r--synapse/storage/schema/main/delta/72/03bg_populate_events_columns.py1
-rw-r--r--synapse/storage/schema/main/delta/72/07force_update_current_state_events_membership.py1
-rw-r--r--synapse/storage/schema/main/delta/73/10_update_sqlite_fts4_tokenizer.py1
-rw-r--r--synapse/storage/schema/main/delta/74/04_membership_tables_event_stream_ordering_triggers.py1
-rw-r--r--synapse/storage/schema/main/delta/78/01_validate_and_update_profiles.py1
-rw-r--r--synapse/storage/schema/main/delta/78/02_validate_and_update_user_filters.py1
-rw-r--r--synapse/storage/schema/main/delta/78/03_remove_unused_indexes_user_filters.py1
-rw-r--r--synapse/storage/schema/main/delta/78/03event_extremities_constraints.py1
-rw-r--r--synapse/storage/schema/main/delta/78/04_add_full_user_id_index_user_filters.py1
-rw-r--r--synapse/storage/schema/main/delta/84/01_auth_links_stats.sql.postgres18
-rw-r--r--synapse/storage/schema/main/delta/84/02_auth_links_index.sql16
-rw-r--r--synapse/storage/types.py1
-rw-r--r--synapse/storage/util/__init__.py1
-rw-r--r--synapse/storage/util/id_generators.py2
-rw-r--r--synapse/storage/util/partial_state_events_tracker.py1
-rw-r--r--synapse/storage/util/sequence.py1
101 files changed, 295 insertions, 33 deletions
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py

index e70e60b014..fcb4d815ea 100644 --- a/synapse/storage/__init__.py +++ b/synapse/storage/__init__.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/_base.py b/synapse/storage/_base.py
index a9a2ebcf46..b127289d8d 100644 --- a/synapse/storage/_base.py +++ b/synapse/storage/_base.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019 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/background_updates.py b/synapse/storage/background_updates.py
index 2faec63717..9df4edee38 100644 --- a/synapse/storage/background_updates.py +++ b/synapse/storage/background_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/controllers/__init__.py b/synapse/storage/controllers/__init__.py
index 7797342903..5ba848efb9 100644 --- a/synapse/storage/controllers/__init__.py +++ b/synapse/storage/controllers/__init__.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 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/controllers/persist_events.py b/synapse/storage/controllers/persist_events.py
index f6b90336bf..69d5999c0a 100644 --- a/synapse/storage/controllers/persist_events.py +++ b/synapse/storage/controllers/persist_events.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019 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/controllers/purge_events.py b/synapse/storage/controllers/purge_events.py
index 7c63681f3c..e794b370c2 100644 --- a/synapse/storage/controllers/purge_events.py +++ b/synapse/storage/controllers/purge_events.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/controllers/state.py b/synapse/storage/controllers/state.py
index 6d15e6638e..99666d79a9 100644 --- a/synapse/storage/controllers/state.py +++ b/synapse/storage/controllers/state.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 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/controllers/stats.py b/synapse/storage/controllers/stats.py
index f382c76e31..9445a86240 100644 --- a/synapse/storage/controllers/stats.py +++ b/synapse/storage/controllers/stats.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/database.py b/synapse/storage/database.py
index 69c9cd6a78..8dc9080842 100644 --- a/synapse/storage/database.py +++ b/synapse/storage/database.py
@@ -1,6 +1,8 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2019 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/__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 diff --git a/synapse/storage/engines/__init__.py b/synapse/storage/engines/__init__.py
index 55d4e7b3b0..53b4cf3d13 100644 --- a/synapse/storage/engines/__init__.py +++ b/synapse/storage/engines/__init__.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/engines/_base.py b/synapse/storage/engines/_base.py
index 80f4eda33d..8c29236b59 100644 --- a/synapse/storage/engines/_base.py +++ b/synapse/storage/engines/_base.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/engines/postgres.py b/synapse/storage/engines/postgres.py
index fe2eb8796e..b9168ee074 100644 --- a/synapse/storage/engines/postgres.py +++ b/synapse/storage/engines/postgres.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/engines/sqlite.py b/synapse/storage/engines/sqlite.py
index 47d0297176..b11094c5c1 100644 --- a/synapse/storage/engines/sqlite.py +++ b/synapse/storage/engines/sqlite.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/keys.py b/synapse/storage/keys.py
index ed3e08721f..740f332ccb 100644 --- a/synapse/storage/keys.py +++ b/synapse/storage/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/prepare_database.py b/synapse/storage/prepare_database.py
index fc05fae273..aaffe5ecc9 100644 --- a/synapse/storage/prepare_database.py +++ b/synapse/storage/prepare_database.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2014 - 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/push_rule.py b/synapse/storage/push_rule.py
index 40fc011bfd..b11ce1c942 100644 --- a/synapse/storage/push_rule.py +++ b/synapse/storage/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/roommember.py b/synapse/storage/roommember.py
index fa72288859..7471f81a19 100644 --- a/synapse/storage/roommember.py +++ b/synapse/storage/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/schema/__init__.py b/synapse/storage/schema/__init__.py
index 132c781f51..c0b925444f 100644 --- a/synapse/storage/schema/__init__.py +++ b/synapse/storage/schema/__init__.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 @@ -18,7 +19,7 @@ # # -SCHEMA_VERSION = 83 # remember to update the list below when updating +SCHEMA_VERSION = 84 # remember to update the list below when updating """Represents the expectations made by the codebase about the database schema This should be incremented whenever the codebase changes its requirements on the diff --git a/synapse/storage/schema/main/delta/20/pushers.py b/synapse/storage/schema/main/delta/20/pushers.py
index 62ee3bd857..b5a8757de0 100644 --- a/synapse/storage/schema/main/delta/20/pushers.py +++ b/synapse/storage/schema/main/delta/20/pushers.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/schema/main/delta/25/fts.py b/synapse/storage/schema/main/delta/25/fts.py
index 71163a4b99..b050cc16a7 100644 --- a/synapse/storage/schema/main/delta/25/fts.py +++ b/synapse/storage/schema/main/delta/25/fts.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/schema/main/delta/27/ts.py b/synapse/storage/schema/main/delta/27/ts.py
index a03affb916..d7f360b6e6 100644 --- a/synapse/storage/schema/main/delta/27/ts.py +++ b/synapse/storage/schema/main/delta/27/ts.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/schema/main/delta/30/as_users.py b/synapse/storage/schema/main/delta/30/as_users.py
index 4e7276af6b..2a3023cd07 100644 --- a/synapse/storage/schema/main/delta/30/as_users.py +++ b/synapse/storage/schema/main/delta/30/as_users.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/schema/main/delta/31/pushers_0.py b/synapse/storage/schema/main/delta/31/pushers_0.py
index c0a23a2c7f..103677b7fe 100644 --- a/synapse/storage/schema/main/delta/31/pushers_0.py +++ b/synapse/storage/schema/main/delta/31/pushers_0.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/schema/main/delta/31/search_update.py b/synapse/storage/schema/main/delta/31/search_update.py
index 992188222f..0e65c9a841 100644 --- a/synapse/storage/schema/main/delta/31/search_update.py +++ b/synapse/storage/schema/main/delta/31/search_update.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/schema/main/delta/33/event_fields.py b/synapse/storage/schema/main/delta/33/event_fields.py
index 0373123368..9c02aeda88 100644 --- a/synapse/storage/schema/main/delta/33/event_fields.py +++ b/synapse/storage/schema/main/delta/33/event_fields.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/schema/main/delta/33/remote_media_ts.py b/synapse/storage/schema/main/delta/33/remote_media_ts.py
index 44eb1d90f9..253ede19ea 100644 --- a/synapse/storage/schema/main/delta/33/remote_media_ts.py +++ b/synapse/storage/schema/main/delta/33/remote_media_ts.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/schema/main/delta/34/cache_stream.py b/synapse/storage/schema/main/delta/34/cache_stream.py
index b7a6731219..fa6b280d95 100644 --- a/synapse/storage/schema/main/delta/34/cache_stream.py +++ b/synapse/storage/schema/main/delta/34/cache_stream.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/schema/main/delta/34/received_txn_purge.py b/synapse/storage/schema/main/delta/34/received_txn_purge.py
index a878758cde..0da5c219cb 100644 --- a/synapse/storage/schema/main/delta/34/received_txn_purge.py +++ b/synapse/storage/schema/main/delta/34/received_txn_purge.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/schema/main/delta/37/remove_auth_idx.py b/synapse/storage/schema/main/delta/37/remove_auth_idx.py
index abf471d223..48b3aaddbb 100644 --- a/synapse/storage/schema/main/delta/37/remove_auth_idx.py +++ b/synapse/storage/schema/main/delta/37/remove_auth_idx.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/schema/main/delta/42/user_dir.py b/synapse/storage/schema/main/delta/42/user_dir.py
index d49a40509d..c98ccaa287 100644 --- a/synapse/storage/schema/main/delta/42/user_dir.py +++ b/synapse/storage/schema/main/delta/42/user_dir.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/schema/main/delta/58/06dlols_unique_idx.py b/synapse/storage/schema/main/delta/58/06dlols_unique_idx.py
index 9cba308189..455f15cab8 100644 --- a/synapse/storage/schema/main/delta/58/06dlols_unique_idx.py +++ b/synapse/storage/schema/main/delta/58/06dlols_unique_idx.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/schema/main/delta/58/11user_id_seq.py b/synapse/storage/schema/main/delta/58/11user_id_seq.py
index 3cd4ea066c..8fb9d02738 100644 --- a/synapse/storage/schema/main/delta/58/11user_id_seq.py +++ b/synapse/storage/schema/main/delta/58/11user_id_seq.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/schema/main/delta/59/01ignored_user.py b/synapse/storage/schema/main/delta/59/01ignored_user.py
index b71ee4d5d6..c7d8b3f277 100644 --- a/synapse/storage/schema/main/delta/59/01ignored_user.py +++ b/synapse/storage/schema/main/delta/59/01ignored_user.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/schema/main/delta/61/03recreate_min_depth.py b/synapse/storage/schema/main/delta/61/03recreate_min_depth.py
index a9e6555f4c..5d3578eaf4 100644 --- a/synapse/storage/schema/main/delta/61/03recreate_min_depth.py +++ b/synapse/storage/schema/main/delta/61/03recreate_min_depth.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/schema/main/delta/68/05partial_state_rooms_triggers.py b/synapse/storage/schema/main/delta/68/05partial_state_rooms_triggers.py
index 35c82c31bd..b4d4b6536b 100644 --- a/synapse/storage/schema/main/delta/68/05partial_state_rooms_triggers.py +++ b/synapse/storage/schema/main/delta/68/05partial_state_rooms_triggers.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 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/schema/main/delta/69/01as_txn_seq.py b/synapse/storage/schema/main/delta/69/01as_txn_seq.py
index 5629eaf32c..d623abc331 100644 --- a/synapse/storage/schema/main/delta/69/01as_txn_seq.py +++ b/synapse/storage/schema/main/delta/69/01as_txn_seq.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2022 Beeper # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/schema/main/delta/72/03bg_populate_events_columns.py b/synapse/storage/schema/main/delta/72/03bg_populate_events_columns.py
index 4c833114b0..3d7a77fb2d 100644 --- a/synapse/storage/schema/main/delta/72/03bg_populate_events_columns.py +++ b/synapse/storage/schema/main/delta/72/03bg_populate_events_columns.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 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/schema/main/delta/72/07force_update_current_state_events_membership.py b/synapse/storage/schema/main/delta/72/07force_update_current_state_events_membership.py
index d1bcaf525d..93543fca7c 100644 --- a/synapse/storage/schema/main/delta/72/07force_update_current_state_events_membership.py +++ b/synapse/storage/schema/main/delta/72/07force_update_current_state_events_membership.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2022 Beeper # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/schema/main/delta/73/10_update_sqlite_fts4_tokenizer.py b/synapse/storage/schema/main/delta/73/10_update_sqlite_fts4_tokenizer.py
index 1f3170f281..76079ad179 100644 --- a/synapse/storage/schema/main/delta/73/10_update_sqlite_fts4_tokenizer.py +++ b/synapse/storage/schema/main/delta/73/10_update_sqlite_fts4_tokenizer.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 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/schema/main/delta/74/04_membership_tables_event_stream_ordering_triggers.py b/synapse/storage/schema/main/delta/74/04_membership_tables_event_stream_ordering_triggers.py
index b911eb8071..6609ef0dac 100644 --- a/synapse/storage/schema/main/delta/74/04_membership_tables_event_stream_ordering_triggers.py +++ b/synapse/storage/schema/main/delta/74/04_membership_tables_event_stream_ordering_triggers.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 2022 Beeper # Copyright (C) 2023 New Vector, Ltd # # This program is free software: you can redistribute it and/or modify diff --git a/synapse/storage/schema/main/delta/78/01_validate_and_update_profiles.py b/synapse/storage/schema/main/delta/78/01_validate_and_update_profiles.py
index 6916be797a..4d39cc770b 100644 --- a/synapse/storage/schema/main/delta/78/01_validate_and_update_profiles.py +++ b/synapse/storage/schema/main/delta/78/01_validate_and_update_profiles.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/schema/main/delta/78/02_validate_and_update_user_filters.py b/synapse/storage/schema/main/delta/78/02_validate_and_update_user_filters.py
index 6c25fd979c..8058937fff 100644 --- a/synapse/storage/schema/main/delta/78/02_validate_and_update_user_filters.py +++ b/synapse/storage/schema/main/delta/78/02_validate_and_update_user_filters.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/schema/main/delta/78/03_remove_unused_indexes_user_filters.py b/synapse/storage/schema/main/delta/78/03_remove_unused_indexes_user_filters.py
index a78fd53f5a..9b0e2a2e12 100644 --- a/synapse/storage/schema/main/delta/78/03_remove_unused_indexes_user_filters.py +++ b/synapse/storage/schema/main/delta/78/03_remove_unused_indexes_user_filters.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/schema/main/delta/78/03event_extremities_constraints.py b/synapse/storage/schema/main/delta/78/03event_extremities_constraints.py
index 2992b9bf7d..ad9c394162 100644 --- a/synapse/storage/schema/main/delta/78/03event_extremities_constraints.py +++ b/synapse/storage/schema/main/delta/78/03event_extremities_constraints.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/schema/main/delta/78/04_add_full_user_id_index_user_filters.py b/synapse/storage/schema/main/delta/78/04_add_full_user_id_index_user_filters.py
index a92c7857f6..03023cbe41 100644 --- a/synapse/storage/schema/main/delta/78/04_add_full_user_id_index_user_filters.py +++ b/synapse/storage/schema/main/delta/78/04_add_full_user_id_index_user_filters.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/schema/main/delta/84/01_auth_links_stats.sql.postgres b/synapse/storage/schema/main/delta/84/01_auth_links_stats.sql.postgres new file mode 100644
index 0000000000..b0b41bd106 --- /dev/null +++ b/synapse/storage/schema/main/delta/84/01_auth_links_stats.sql.postgres
@@ -0,0 +1,18 @@ +-- +-- This file is licensed under the Affero General Public License (AGPL) version 3. +-- +-- Copyright (C) 2023 New Vector, Ltd +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero General Public License as +-- published by the Free Software Foundation, either version 3 of the +-- License, or (at your option) any later version. +-- +-- See the GNU Affero General Public License for more details: +-- <https://www.gnu.org/licenses/agpl-3.0.html>. + +-- Force the statistics for these tables to show that the number of distinct +-- chain IDs are proportional to the total rows, as postgres has trouble +-- figuring that out by itself. +ALTER TABLE event_auth_chain_links ALTER origin_chain_id SET (n_distinct = -0.5); +ALTER TABLE event_auth_chain_links ALTER target_chain_id SET (n_distinct = -0.5); diff --git a/synapse/storage/schema/main/delta/84/02_auth_links_index.sql b/synapse/storage/schema/main/delta/84/02_auth_links_index.sql new file mode 100644
index 0000000000..6936e3d05b --- /dev/null +++ b/synapse/storage/schema/main/delta/84/02_auth_links_index.sql
@@ -0,0 +1,16 @@ +-- +-- This file is licensed under the Affero General Public License (AGPL) version 3. +-- +-- Copyright (C) 2023 New Vector, Ltd +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero General Public License as +-- published by the Free Software Foundation, either version 3 of the +-- License, or (at your option) any later version. +-- +-- See the GNU Affero General Public License for more details: +-- <https://www.gnu.org/licenses/agpl-3.0.html>. + + +INSERT INTO background_updates (ordering, update_name, progress_json) VALUES + (8402, 'event_auth_chain_links_origin_index', '{}'); diff --git a/synapse/storage/types.py b/synapse/storage/types.py
index 5c51b492b2..b4e0a8f576 100644 --- a/synapse/storage/types.py +++ b/synapse/storage/types.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/util/__init__.py b/synapse/storage/util/__init__.py
index 3d833a2e44..fcd2134c89 100644 --- a/synapse/storage/util/__init__.py +++ b/synapse/storage/util/__init__.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/util/id_generators.py b/synapse/storage/util/id_generators.py
index 2805062b03..fadc75cc80 100644 --- a/synapse/storage/util/id_generators.py +++ b/synapse/storage/util/id_generators.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/util/partial_state_events_tracker.py b/synapse/storage/util/partial_state_events_tracker.py
index 1dc85fccf6..f8addf38f6 100644 --- a/synapse/storage/util/partial_state_events_tracker.py +++ b/synapse/storage/util/partial_state_events_tracker.py
@@ -1,6 +1,7 @@ # # This file is licensed under the Affero General Public License (AGPL) version 3. # +# Copyright 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/util/sequence.py b/synapse/storage/util/sequence.py
index 7654084b94..f57e7ec41c 100644 --- a/synapse/storage/util/sequence.py +++ b/synapse/storage/util/sequence.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