summary refs log tree commit diff
path: root/synapse/storage (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Fix `UndefinedColumn: column "key_json" does not exist` errors when handling ↵David Robertson2022-11-291-0/+1
| | | | users with more than 50 non-E2E devices (#14580)
* POC delete stale non-e2e devices for users (#14038)Erik Johnston2022-11-291-1/+66
| | | | | | | | This should help reduce the number of devices e.g. simple bots the repeatedly login rack up. We only delete non-e2e devices as they should be safe to delete, whereas if we delete e2e devices for a user we may accidentally break their ability to receive e2e keys for a message. Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com> Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
* Support MSC1767's `content.body` behaviour; Add base rules from MSC3933 (#14524)Travis Ralston2022-11-281-1/+4
| | | | | | | | | | | * Support MSC1767's `content.body` behaviour in push rules * Add the base rules from MSC3933 * Changelog entry * Flip condition around for finding `m.markup` * Remove forgotten import
* Use `device_one_time_keys_count` to match MSC3202 (#14565)Andrew Ferrazzutti2022-11-282-9/+9
| | | | | | | | | | | | | | | | | | | * Use `device_one_time_keys_count` to match MSC3202 Rename the `device_one_time_key_counts` key in responses to `device_one_time_keys_count` to match the name specified by MSC3202. Also change related variable/class names for consistency. Signed-off-by: Andrew Ferrazzutti <andrewf@element.io> * Update changelog.d/14565.misc * Revert name change for `one_time_key_counts` key as this is a different key altogether from `device_one_time_keys_count`, which is used for `/sync` instead of appservice transactions. Signed-off-by: Andrew Ferrazzutti <andrewf@element.io>
* Remove option to skip locking of tables during emulated upserts (#14469)Sean Quah2022-11-289-74/+18
| | | | | | | | | | | | | | | | | | To perform an emulated upsert into a table safely, we must either: * lock the table, * be the only writer upserting into the table * or rely on another unique index being present. When the 2nd or 3rd cases were applicable, we previously avoided locking the table as an optimization. However, as seen in #14406, it is easy to slip up when adding new schema deltas and corrupt the database. The only time we lock when performing emulated upserts is while waiting for background updates on postgres. On sqlite, we do no locking at all. Let's remove the option to skip locking tables, so that we don't shoot ourselves in the foot again. Signed-off-by: Sean Quah <seanq@matrix.org>
* Fix crash admin media list api when info is None (#14537)schmop2022-11-241-1/+5
| | | Fixes https://github.com/matrix-org/synapse/issues/14536
* Add another index to `device_lists_changes_in_room` (#14534)Erik Johnston2022-11-232-0/+27
| | | | This helps avoid reading unnecessarily large amounts of data from the table when querying with a set of room IDs.
* Optimize `filter_events_for_client` for faster `/messages` - v2 (#14527)Eric Eastwood2022-11-221-20/+79
| | | Fix #14108
* Track unconverted device list outbound pokes using a position instead (#14516)Sean Quah2022-11-223-44/+129
| | | | | | | | | | | | | | | | | | | | | When a local device list change is added to `device_lists_changes_in_room`, the `converted_to_destinations` flag is set to `FALSE` and the `_handle_new_device_update_async` background process is started. This background process looks for unconverted rows in `device_lists_changes_in_room`, copies them to `device_lists_outbound_pokes` and updates the flag. To update the `converted_to_destinations` flag, the database performs a `DELETE` and `INSERT` internally, which fragments the table. To avoid this, track unconverted rows using a `(stream ID, room ID)` position instead of the flag. From now on, the `converted_to_destinations` column indicates rows that need converting to outbound pokes, but does not indicate whether the conversion has already taken place. Closes #14037. Signed-off-by: Sean Quah <seanq@matrix.org>
* Batch fetch bundled references (#14508)Patrick Cloke2022-11-223-8/+71
| | | | | | | | | Avoid an n+1 query problem and fetch the bundled aggregations for m.reference relations in a single query instead of a query per event. This applies similar logic for as was previously done for edits in 8b309adb436c162510ed1402f33b8741d71fc058 (#11660; threads in b65acead428653b988351ae8d7b22127a22039cd (#11752); and annotations in 1799a54a545618782840a60950ef4b64da9ee24d (#14491).
* Batch fetch bundled annotations (#14491)Patrick Cloke2022-11-221-54/+85
| | | | | | | | Avoid an n+1 query problem and fetch the bundled aggregations for m.annotation relations in a single query instead of a query per event. This applies similar logic for as was previously done for edits in 8b309adb436c162510ed1402f33b8741d71fc058 (#11660) and threads in b65acead428653b988351ae8d7b22127a22039cd (#11752).
* Fix check to ignore blank lines in incoming TCP replication (#14449)Andrew Morgan2022-11-171-3/+3
|
* Reintroduce #14376, with bugfix for monoliths (#14468)David Robertson2022-11-167-100/+73
| | | | | | | | | | | | | | | | | | | | | | * Add tests for StreamIdGenerator * Drive-by: annotate all defs * Revert "Revert "Remove slaved id tracker (#14376)" (#14463)" This reverts commit d63814fd736fed5d3d45ff3af5e6d3bfae50c439, which in turn reverted 36097e88c4da51fce6556a58c49bd675f4cf20ab. This restores the latter. * Fix StreamIdGenerator not handling unpersisted IDs Spotted by @erikjohnston. Closes #14456. * Changelog Co-authored-by: Nick Mills-Barrett <nick@fizzadar.com> Co-authored-by: Erik Johnston <erik@matrix.org>
* Remove redundant types from comments. (#14412)Patrick Cloke2022-11-1610-40/+37
| | | | | | | Remove type hints from comments which have been added as Python type hints. This helps avoid drift between comments and reality, as well as removing redundant information. Also adds some missing type hints which were simple to fill in.
* Fix background updates failing to add unique indexes on receipts (#14453)Sean Quah2022-11-161-24/+147
| | | | | | | | | | | | | | | | | | | | | | As part of the database migration to support threaded receipts, there is a possible window in between `73/08thread_receipts_non_null.sql.postgres` removing the original unique constraints on `receipts_linearized` and `receipts_graph` and the `reeipts_linearized_unique_index` and `receipts_graph_unique_index` background updates from `72/08thread_receipts.sql` completing where the unique constraints on `receipts_linearized` and `receipts_graph` are missing. Any emulated upserts on these tables must therefore be performed with a lock held, otherwise duplicate rows can end up in the tables when there are concurrent emulated upserts. Fix the missing lock. Note that emulated upserts no longer happen by default on sqlite, since the minimum supported version of sqlite supports native upserts by default now. Finally, clean up any duplicate receipts that may have crept in before trying to create the `receipts_graph_unique_index` and `receipts_linearized_unique_index` unique indexes. Signed-off-by: Sean Quah <seanq@matrix.org>
* Revert "Remove slaved id tracker (#14376)" (#14463)Erik Johnston2022-11-167-73/+100
| | | This reverts commit 36097e88c4da51fce6556a58c49bd675f4cf20ab.
* Include heroes in partial join responses' state (#14442)David Robertson2022-11-151-0/+30
| | | | | | | | | | | * Pull out hero selection logic * Include heroes in partial join response's state * Changelog * Fixup trial test * Remove TODO
* Update docstring to clarify that `get_partial_state_events_batch` does not ↵reivilibre2022-11-151-1/+9
| | | | just give you completely arbitrary partial-state events. (#14417)
* Remove slaved id tracker (#14376)Nick Mills-Barrett2022-11-147-100/+73
| | | | | This matches the multi instance writer ID generator class which can both handle advancing the current token over replication and by calling the database.
* Clean-up events persistance code (#14411)Patrick Cloke2022-11-142-8/+3
| | | | By removing unused variables and making some arguments required which are always provided.
* Merge/remove `Slaved*` stores into `WorkerStores` (#14375)Nick Mills-Barrett2022-11-117-58/+139
|
* Fix PostgreSQL sometimes using table scans for `event_search` (#14409)Sean Quah2022-11-101-0/+33
| | | | | | | | | | | PostgreSQL may underestimate the number of distinct `room_id`s in `event_search`, which can cause it to use table scans for queries for multiple rooms. Fix this by setting `n_distinct` on the column. Resolves #14402. Signed-off-by: Sean Quah <seanq@matrix.org>
* Drop support for Postgres 10 in full text search code. (#14397)Patrick Cloke2022-11-092-43/+23
|
* Remove support for PostgreSQL 10 (#14392)Sean Quah2022-11-081-2/+2
| | | Signed-off-by: Sean Quah <seanq@matrix.org>
* Fix background update table-scanning `events` (#14374)Richard van der Hoff2022-11-071-8/+8
| | | | | When this background update did its last batch, it would try to update all the events that had been inserted since the bgupdate started, which could cause a table-scan. Make sure we limit the update correctly.
* Bump flake8-bugbear from 22.9.23 to 22.10.27 (#14329)dependabot[bot]2022-11-041-1/+1
| | | | | Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: GitHub Actions <github-actions[bot]@users.noreply.github.com> Co-authored-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
* Implement MSC3912: Relation-based redactions (#14260)Brendan Abolivier2022-11-031-0/+36
| | | Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
* Support OIDC backchannel logouts (#11414)Quentin Gliech2022-10-311-0/+21
| | | | | | | If configured an OIDC IdP can log a user's session out of Synapse when they log out of the identity provider. The IdP sends a request directly to Synapse (and must be configured with an endpoint) when a user logs out.
* Prevent federation user keys query from returning device names if disallowed ↵Andrew Morgan2022-10-281-5/+12
| | | | (#14304)
* Switch search SQL to triple-quote strings. (#14311)Patrick Cloke2022-10-281-89/+99
| | | | For ease of reading we switch from concatenated strings to triple quote strings.
* Check appservice user interest against the local users instead of all users ↵Eric Eastwood2022-10-272-2/+18
| | | | (`get_users_in_room` mis-use) (#13958)
* Fix tests for change in PostgreSQL 14 behavior change. (#14310)Patrick Cloke2022-10-271-3/+2
| | | | | | | PostgreSQL 14 changed the behavior of `websearch_to_tsquery` to improve some behaviour. The tests were hitting those edge-cases about handling of hanging double quotes. This fixes the tests to take into account the PostgreSQL version.
* Fix presence bug introduced in 1.64 by #13313 (#14243)Mathieu Velten2022-10-271-2/+1
| | | | | | | | | | | | | * Fix presence bug introduced in 1.64 by #13313 Signed-off-by: Mathieu Velten <mathieuv@matrix.org> * Add changelog * Add DISTINCT * Apply suggestions from code review Signed-off-by: Mathieu Velten <mathieuv@matrix.org>
* Save login tokens in database (#13844)Quentin Gliech2022-10-262-1/+190
| | | | | | | | | | | * Save login tokens in database Signed-off-by: Quentin Gliech <quenting@element.io> * Add upgrade notes * Track login token reuse in a Prometheus metric Signed-off-by: Quentin Gliech <quenting@element.io>
* Unified search query syntax using the full-text search capabilities of the ↵James Salter2022-10-253-35/+240
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | underlying DB. (#11635) Support a unified search query syntax which leverages more of the full-text search of each database supported by Synapse. Supports, with the same syntax across Postgresql 11+ and Sqlite: - quoted "search terms" - `AND`, `OR`, `-` (negation) operators - Matching words based on their stem, e.g. searches for "dog" matches documents containing "dogs". This is achieved by - If on postgresql 11+, pass the user input to `websearch_to_tsquery` - If on sqlite, manually parse the query and transform it into the sqlite-specific query syntax. Note that postgresql 10, which is close to end-of-life, falls back to using `phraseto_tsquery`, which only supports a subset of the features. Multiple terms separated by a space are implicitly ANDed. Note that: 1. There is no escaping of full-text syntax that might be supported by the database; e.g. `NOT`, `NEAR`, `*` in sqlite. This runs the risk that people might discover this as accidental functionality and depend on something we don't guarantee. 2. English text is assumed for stemming. To support other languages, either the target language needs to be known at the time of indexing the message (via room metadata, or otherwise), or a separate index for each language supported could be created. Sqlite docs: https://www.sqlite.org/fts3.html#full_text_index_queries Postgres docs: https://www.postgresql.org/docs/11/textsearch-controls.html
* Merge branch 'release-v1.70' into developOlivier Wilkinson (reivilibre)2022-10-252-14/+58
|\
| * Revert behavior change for bundling edits of non-message events (#14283)Patrick Cloke2022-10-241-4/+7
| |
| * Properly update the threads table when thread events are redacted. (#14248)Patrick Cloke2022-10-211-10/+51
| | | | | | | | | | | | | | | | | | When the last event in a thread is redacted we need to update the threads table: * Find the new latest event in the thread and store it into the table; or * Remove the thread from the table if it is no longer a thread (i.e. all events in the thread were redacted).
* | Implementation for MSC3664: Pushrules for relations (#11804)DeepBlueV7.X2022-10-251-4/+11
| |
* | Enable WAL for SQLite (#13897)asymmetric2022-10-251-0/+4
| | | | | | Signed-off-by: Lorenzo Manacorda <lorenzo@mailbox.org>
* | Add debugging to help diagnose lost device-list-update (#14268)Richard van der Hoff2022-10-241-17/+37
| |
* | Show erasure status when listing users in the Admin API (#14205)Tadeusz Sośnierz2022-10-211-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Show erasure status when listing users in the Admin API * Use USING when joining erased_users * Add changelog entry * Revert "Use USING when joining erased_users" This reverts commit 30bd2bf106415caadcfdbdd1b234ef2b106cc394. * Make the erased check work on postgres * Add a testcase for showing erased user status * Appease the style linter * Explicitly convert `erased` to bool to make SQLite consistent with Postgres This also adds us an easy way in to fix the other accidentally integered columns. * Move erasure status test to UsersListTestCase * Include user erased status when fetching user info via the admin API * Document the erase status in user_admin_api * Appease the linter and mypy * Signpost comments in tests Co-authored-by: Tadeusz Sośnierz <tadeusz@sosnierz.com> Co-authored-by: David Robertson <david.m.robertson1@gmail.com>
* | Bump flake8-bugbear from 21.3.2 to 22.9.23 (#14042)dependabot[bot]2022-10-191-2/+2
|/ | | | | Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Erik Johnston <erik@matrix.org> Co-authored-by: David Robertson <davidr@element.io>
* Fix MSC3030 `/timestamp_to_event` returning `outliers` that it has no idea ↵Eric Eastwood2022-10-181-21/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | whether are near a gap or not (#14215) Fix MSC3030 `/timestamp_to_event` endpoint returning `outliers` that it has no idea whether are near a gap or not (and therefore unable to determine whether it's actually the closest event). The reason Synapse doesn't know whether an `outlier` is next to a gap is because our gap checks rely on entries in the `event_edges`, `event_forward_extremeties`, and `event_backward_extremities` tables which is [not the case for `outliers`](https://github.com/matrix-org/synapse/blob/2c63cdcc3f1aa4625e947de3c23e0a8133c61286/docs/development/room-dag-concepts.md#outliers). Also fixes MSC3030 Complement `can_paginate_after_getting_remote_event_from_timestamp_to_event_endpoint` test flake. Although this acted flakey in Complement, if `sync_partial_state` raced and beat us before `/timestamp_to_event`, then even if we retried the failing `/context` request it wouldn't work until we made this Synapse change. With this PR, Synapse will never return an `outlier` event so that test will always go and ask over federation. Fix https://github.com/matrix-org/synapse/issues/13944 ### Why did this fail before? Why was it flakey? Sleuthing the server logs on the [CI failure](https://github.com/matrix-org/synapse/actions/runs/3149623842/jobs/5121449357#step:5:5805), it looks like `hs2:/timestamp_to_event` found `$NP6-oU7mIFVyhtKfGvfrEQX949hQX-T-gvuauG6eurU` as an `outlier` event locally. Then when we went and asked for it via `/context`, since it's an `outlier`, it was filtered out of the results -> `You don't have permission to access that event.` This is reproducible when `sync_partial_state` races and persists `$NP6-oU7mIFVyhtKfGvfrEQX949hQX-T-gvuauG6eurU` as an `outlier` before we evaluate `get_event_for_timestamp(...)`. To consistently reproduce locally, just add a delay at the [start of `get_event_for_timestamp(...)`](https://github.com/matrix-org/synapse/blob/cb20b885cb4bd1648581dd043a184d86fc8c7a00/synapse/handlers/room.py#L1470-L1496) so it always runs after `sync_partial_state` completes. ```py from twisted.internet import task as twisted_task d = twisted_task.deferLater(self.hs.get_reactor(), 3.5) await d ``` In a run where it passes, on `hs2`, `get_event_for_timestamp(...)` finds a different event locally which is next to a gap and we request from a closer one from `hs1` which gets backfilled. And since the backfilled event is not an `outlier`, it's returned as expected during `/context`. With this PR, Synapse will never return an `outlier` event so that test will always go and ask over federation.
* Fix hiding devices names over federation (#10015)Aaron Raimist2022-10-181-2/+8
| | | | | | And don't include blank opentracing stuff in device list updates. Signed-off-by: Aaron Raimist <aaron@raim.ist>
* Update the thread_id right before use (in case the bg update hasn't ↵Patrick Cloke2022-10-184-134/+111
| | | | | | | | finished) (#14222) This avoids running a forced-update of a null thread_id rows. An index is added (in the background) to hopefully make this easier in the future.
* When restarting a partial join resync, prioritise the server which actioned ↵David Robertson2022-10-183-7/+56
| | | | a partial join (#14126)
* Avoid checking the event cache when backfilling events (#14164)Andrew Morgan2022-10-181-1/+1
|
* Remove `_get_events_cache` check optimisation from `_have_seen_events_dict` ↵Andrew Morgan2022-10-181-18/+13
| | | | (#14161)
* Support filtering the /messages API by relation type (MSC3874). (#14148)Patrick Cloke2022-10-171-2/+27
| | | Gated behind an experimental configuration flag.
* Invalidate rooms for user caches when receiving membership events (#14155)Nick Mills-Barrett2022-10-171-0/+4
| | | | | This should fix a race where the event notification comes in over replication before the state replication, leaving a window during which a sync may get an incorrect list of rooms for the user.
* Stop getting missing `prev_events` after we already know their signature is ↵Eric Eastwood2022-10-151-0/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | invalid (#13816) While https://github.com/matrix-org/synapse/pull/13635 stops us from doing the slow thing after we've already done it once, this PR stops us from doing one of the slow things in the first place. Related to - https://github.com/matrix-org/synapse/issues/13622 - https://github.com/matrix-org/synapse/pull/13635 - https://github.com/matrix-org/synapse/issues/13676 Part of https://github.com/matrix-org/synapse/issues/13356 Follow-up to https://github.com/matrix-org/synapse/pull/13815 which tracks event signature failures. With this PR, we avoid the call to the costly `_get_state_ids_after_missing_prev_event` because the signature failure will count as an attempt before and we filter events based on the backoff before calling `_get_state_ids_after_missing_prev_event` now. For example, this will save us 156s out of the 185s total that this `matrix.org` `/messages` request. If you want to see the full Jaeger trace of this, you can drag and drop this `trace.json` into your own Jaeger, https://gist.github.com/MadLittleMods/4b12d0d0afe88c2f65ffcc907306b761 To explain this exact scenario around `/messages` -> backfill, we call `/backfill` and first check the signatures of the 100 events. We see bad signature for `$luA4l7QHhf_jadH3mI-AyFqho0U2Q-IXXUbGSMq6h6M` and `$zuOn2Rd2vsC7SUia3Hp3r6JSkSFKcc5j3QTTqW_0jDw` (both member events). Then we process the 98 events remaining that have valid signatures but one of the events references `$luA4l7QHhf_jadH3mI-AyFqho0U2Q-IXXUbGSMq6h6M` as a `prev_event`. So we have to do the whole `_get_state_ids_after_missing_prev_event` rigmarole which pulls in those same events which fail again because the signatures are still invalid. - `backfill` - `outgoing-federation-request` `/backfill` - `_check_sigs_and_hash_and_fetch` - `_check_sigs_and_hash_and_fetch_one` for each event received over backfill - ❗ `$luA4l7QHhf_jadH3mI-AyFqho0U2Q-IXXUbGSMq6h6M` fails with `Signature on retrieved event was invalid.`: `unable to verify signature for sender domain xxx: 401: Failed to find any key to satisfy: _FetchKeyRequest(...)` - ❗ `$zuOn2Rd2vsC7SUia3Hp3r6JSkSFKcc5j3QTTqW_0jDw` fails with `Signature on retrieved event was invalid.`: `unable to verify signature for sender domain xxx: 401: Failed to find any key to satisfy: _FetchKeyRequest(...)` - `_process_pulled_events` - `_process_pulled_event` for each validated event - ❗ Event `$Q0iMdqtz3IJYfZQU2Xk2WjB5NDF8Gg8cFSYYyKQgKJ0` references `$luA4l7QHhf_jadH3mI-AyFqho0U2Q-IXXUbGSMq6h6M` as a `prev_event` which is missing so we try to get it - `_get_state_ids_after_missing_prev_event` - `outgoing-federation-request` `/state_ids` - ❗ `get_pdu` for `$luA4l7QHhf_jadH3mI-AyFqho0U2Q-IXXUbGSMq6h6M` which fails the signature check again - ❗ `get_pdu` for `$zuOn2Rd2vsC7SUia3Hp3r6JSkSFKcc5j3QTTqW_0jDw` which fails the signature check
* Merge remote-tracking branch 'origin/release-v1.69' into developPatrick Cloke2022-10-141-13/+59
|\
| * Fix background update to use an index (#14181)Erik Johnston2022-10-141-11/+51
| |
| * Optimise the event_push_backfill_thread_id bg job (#14172)David Robertson2022-10-131-2/+8
| | | | | | Co-authored-by: Erik Johnston <erik@matrix.org>
| * Fix rotating existing notifications in push summary (#14138)Erik Johnston2022-10-111-5/+15
| | | | | | | | | | Broke by #14045. Fixes #14120. Introduced in v1.69.0rc2.
| * Fix backwards compatibility with upcoming threads schema changes. (#14045)Patrick Cloke2022-10-051-11/+23
| | | | | | | | Ensure that the upsert will work properly by first updating any existing rows (in the same way that the background update to backfill data works).
* | Accept threaded receipts for events related to the root event. (#14174)Patrick Cloke2022-10-142-6/+93
| | | | | | | | | | | | | | | | | | The root node of a thread (and events related to it) are considered "part of a thread" when validating receipts. This allows clients which show the root node in both the main timeline and the threaded timeline to easily send receipts in either. Note that threaded notifications are not created for these events, these events created notifications on the main timeline.
* | Do not allow a None-limit on PaginationConfig. (#14146)Patrick Cloke2022-10-141-2/+0
| | | | | | | | | | | | | | The callers either set a default limit or manually handle a None-limit later on (by setting a default value). Update the callers to always instantiate PaginationConfig with a default limit and then assume the limit is non-None.
* | Properly invalidate get_thread_id cache. (#14163)Patrick Cloke2022-10-141-0/+1
| | | | | | This was missed in 2b6d41ebd685fb546e52acdbcb0024dfcf5a5db1 (#13824).
* | Fix sqlite syntax for upserts. (#14171)Patrick Cloke2022-10-131-1/+1
| |
* | Properly return the thread ID down sync. (#14159)Patrick Cloke2022-10-131-2/+2
| | | | | | | | | | Fix a broken conflict in e6e876b9b158f47811b6dfedd8783f658ce960a4, by not stomping over a field right after creating it.
* | Add an API for listing threads in a room. (#13394)Patrick Cloke2022-10-134-4/+231
| | | | | | | | | | | | | | | | | | Implement the /threads endpoint from MSC3856. This is currently unstable and behind an experimental configuration flag. It includes a background update to backfill data, results from the /threads endpoint will be partial until that finishes.
* | Return the thread ID properly down sync. (#14159)Patrick Cloke2022-10-121-0/+2
| | | | | | | | | | A receipt's thread ID, if one exists, should be added to the body of a receipt.
* | Return the main timeline for events which are not part of a thread. (#14140)Patrick Cloke2022-10-121-5/+7
| | | | | | | | Fixes a bug where threaded receipts could not be sent for the main timeline.
* | Batch up calls to `get_rooms_for_users` (#14109)Nick Mills-Barrett2022-10-121-1/+16
| |
* | Remove the experimental implementation of MSC3772. (#14094)Patrick Cloke2022-10-124-72/+4
| | | | | | MSC3772 has been abandoned.
* | Fix a bug where redactions were not being sent over federation if we did not ↵Shay2022-10-112-19/+24
| | | | | | | | have the original event. (#13813)
* | Apply & bundle edits for non-message events. (#14034)Patrick Cloke2022-10-071-7/+4
| | | | | | | | | | | | | | Fixes two related bugs: * No edit information was bundled for events which aren't `m.room.message`. * `m.new_content` was not applied for those events.
* | Fix handling of public rooms filter with a network tuple. (#14053)Patrick Cloke2022-10-051-17/+26
| | | | | | | | | | | | | | | | Fixes two related bugs: * The handling of `[null]` for a `room_types` filter was incorrect. * The ordering of arguments when providing both a network tuple and room type field was incorrect.
* | Use threaded receipts when fetching events for push. (#13878)Patrick Cloke2022-10-041-23/+57
| | | | | | | | Update the HTTP and email pushers to consider threaded read receipts when fetching unread events.
* | Recursively fetch the thread for receipts & notifications. (#13824)Patrick Cloke2022-10-041-0/+36
| | | | | | | | | | | | Consider an event to be part of a thread if you can follow a chain of relations up to a thread root. Part of MSC3773 & MSC3771.
* | Mark events as read using threaded read receipts from MSC3771. (#13877)Patrick Cloke2022-10-043-61/+315
| | | | | | | | Applies the proper logic for unthreaded and threaded receipts to either apply to all events in the room or only events in the same thread, respectively.
* | Track notification counts per thread (implement MSC3773). (#13776)Patrick Cloke2022-10-046-77/+268
| | | | | | | | | | | | | | | | When retrieving counts of notifications segment the results based on the thread ID, but choose whether to return them as individual threads or as a single summed field by letting the client opt-in via a sync flag. The summarization code is also updated to be per thread, instead of per room.
* | Disable pushing for server ACL events (MSC3786). (#13997)Patrick Cloke2022-10-041-7/+2
|/ | | | | | Switches to the stable identifier for MSC3786 and enables it by default. This disables pushes of m.room.server_acl events.
* Clear out old rows from `event_push_actions_staging` (#14020)Erik Johnston2022-10-034-1/+104
| | | On matrix.org we have ~5 million stale rows in `event_push_actions_staging`, let's add a background job to make sure we clear them out.
* Fix bug where we didn't delete staging push actions (#14014)Erik Johnston2022-10-031-1/+1
| | | Introduced in #13719
* Add cache to `get_partial_state_servers_at_join` (#14013)Erik Johnston2022-10-031-0/+7
|
* Refactor `_get_e2e_device_keys_txn` to split large queries (#13956)Sean Quah2022-10-032-29/+114
| | | | | | | | | | Instead of running a single large query, run a single query for user-only lookups and additional queries for batches of user device lookups. Resolves #13580. Signed-off-by: Sean Quah <seanq@matrix.org>
* Update mypy and mypy-zope, attempt 3 (#13993)David Robertson2022-09-302-17/+7
| | | Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
* Revert "Update mypy and mypy-zope (#13925)"David Robertson2022-09-302-7/+17
| | | | This reverts commit 6d543d6d9f56e39199b7e460d0081b02d61f12be.
* Update mypy and mypy-zope (#13925)David Robertson2022-09-302-17/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Update mypy and mypy-zope * Unignore assigning to LogRecord attributes Presumably https://github.com/python/typeshed/pull/8064 makes this ok Cherry-picked from #13521 * Remove unused ignores due to mypy ParamSpec fixes https://github.com/python/mypy/pull/12668 Cherry-picked from #13521 * Remove additional unused ignores * Fix new mypy complaints related to `assertGreater` Presumably due to https://github.com/python/typeshed/pull/8077 * Changelog * Reword changelog Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com> Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
* Fix performance regression in `get_users_in_room` (#13972)Erik Johnston2022-09-302-68/+91
| | | | | Fixes #13942. Introduced in #13575. Basically, let's only get the ordered set of hosts out of the DB if we need an ordered set of hosts. Since we split the function up the caching won't be as good, but I think it will still be fine as e.g. multiple backfill requests for the same room will hit the cache.
* Fix overflows in /messages backfill calculation (#13936)David Robertson2022-09-301-29/+53
| | | | | | | | * Reproduce bug * Compute `least_function` first * Substitute `least_function` with an f-string * Bugfix: avoid overflow Co-authored-by: Eric Eastwood <erice@element.io>
* Update UPSERT comment now that native upserts are the default (#13924)David Robertson2022-09-291-10/+50
|
* Optimise get_rooms_for_user (drop with_stream_ordering) (#13787)Nick Mills-Barrett2022-09-293-61/+58
|
* Allow admins to require a manual approval process before new accounts can be ↵Brendan Abolivier2022-09-293-19/+160
| | | | used (using MSC3866) (#13556)
* Explicit cast to enforce type hints. (#13939)Patrick Cloke2022-09-291-4/+4
|
* Clarify that a method returns only unthreaded receipts. (#13937)Patrick Cloke2022-09-292-40/+8
| | | | | By renaming it and updating the docstring. Additionally, refactors a method which is used only by tests.
* Handle local device list updates during partial join (#13934)Erik Johnston2022-09-282-13/+58
|
* Limit and filter the number of backfill points to get from the database (#13879)Eric Eastwood2022-09-281-12/+78
| | | | | | | | | There is no need to grab thousands of backfill points when we only need 5 to make the `/backfill` request with. We need to grab a few extra in case the first few aren't visible in the history. Previously, we grabbed thousands of backfill points from the database, then sorted and filtered them in the app. Fetching the 4.6k backfill points for `#matrix:matrix.org` from the database takes ~50ms - ~570ms so it's not like this saves a lot of time 🤷. But it might save us more time now that `get_backfill_points_in_room`/`get_insertion_event_backward_extremities_in_room` are more complicated after https://github.com/matrix-org/synapse/pull/13635 This PR moves the filtering and limiting to the SQL query so we just have less data to work with in the first place. Part of https://github.com/matrix-org/synapse/issues/13356
* Revert "Stop returning an unused column when handling new receipts. ↵Patrick Cloke2022-09-281-2/+2
| | | | | | | (#13933)" (#13935) This reverts commit 7766bd5b354cd4ea1a33351ba320e54a14d3aeac (#13933). The unused column is actually used, but much further down in the function.
* Stop returning an unused column when handling new receipts. (#13933)Patrick Cloke2022-09-281-2/+2
|
* Handle remote device list updates during partial join (#13913)Erik Johnston2022-09-283-0/+103
| | | | | | | c.f. #12993 (comment), point 3 This stores all device list updates that we receive while partial joins are ongoing, and processes them once we have the full state. Note: We don't actually process the device lists in the same ways as if we weren't partially joined. Instead of updating the device list remote cache, we simply notify local users that a change in the remote user's devices has happened. I think this is safe as if the local user requests the keys for the remote user and we don't have them we'll simply fetch them as normal.
* fix: Push notifications for invite over federation (#13719)Kateřina Churanová2022-09-282-9/+11
|
* Fix `have_seen_event` cache not being invalidated (#13863)Eric Eastwood2022-09-271-18/+22
| | | | | | | | | | | | | | | | | | | | | Fix https://github.com/matrix-org/synapse/issues/13856 Fix https://github.com/matrix-org/synapse/issues/13865 > Discovered while trying to make Synapse fast enough for [this MSC2716 test for importing many batches](https://github.com/matrix-org/complement/pull/214#discussion_r741678240). As an example, disabling the `have_seen_event` cache saves 10 seconds for each `/messages` request in that MSC2716 Complement test because we're not making as many federation requests for `/state` (speeding up `have_seen_event` itself is related to https://github.com/matrix-org/synapse/issues/13625) > > But this will also make `/messages` faster in general so we can include it in the [faster `/messages` milestone](https://github.com/matrix-org/synapse/milestone/11). > > *-- https://github.com/matrix-org/synapse/issues/13856* ### The problem `_invalidate_caches_for_event` doesn't run in monolith mode which means we never even tried to clear the `have_seen_event` and other caches. And even in worker mode, it only runs on the workers, not the master (AFAICT). Additionally there was bug with the key being wrong so `_invalidate_caches_for_event` never invalidates the `have_seen_event` cache even when it does run. Because we were using the `@cachedList` wrong, it was putting items in the cache under keys like `((room_id, event_id),)` with a `set` in a `set` (ex. `(('!TnCIJPKzdQdUlIyXdQ:test', '$Iu0eqEBN7qcyF1S9B3oNB3I91v2o5YOgRNPwi_78s-k'),)`) and we we're trying to invalidate with just `(room_id, event_id)` which did nothing.
* Add new columns tracking when we partial-joined (#13892)David Robertson2022-09-272-2/+73
|
* Handle the case of remote users leaving a partial join room for device lists ↵Erik Johnston2022-09-275-106/+83
| | | | (#13885)
* Improve tests for get_unread_push_actions_for_user_in_range_*. (#13893)Patrick Cloke2022-09-261-14/+24
| | | | | * Adds a docstring. * Reduces a small amount of duplicated code. * Improves tests.
* Snapshot schema 72 (#13873)David Robertson2022-09-2611-8/+2118
| | | Including another batch of fixes to the schema dump script
* Simplify cache invalidation after event persist txn (#13796)Nick Mills-Barrett2022-09-263-119/+51
| | | | | This moves all the invalidations into a single place and de-duplicates the code involved in invalidating caches for a given event by using the base class method.
* Only try to backfill event if we haven't tried before recently (#13635)Eric Eastwood2022-09-231-41/+147
| | | | | | | | | | Only try to backfill event if we haven't tried before recently (exponential backoff). No need to keep trying the same backfill point that fails over and over. Fix https://github.com/matrix-org/synapse/issues/13622 Fix https://github.com/matrix-org/synapse/issues/8451 Follow-up to https://github.com/matrix-org/synapse/pull/13589 Part of https://github.com/matrix-org/synapse/issues/13356
* Faster room joins: Avoid blocking `/keys/changes` (#13888)Sean Quah2022-09-231-1/+6
| | | | | | | | | Part of the work for #12993. Once #12993 is fully resolved, we expect `/keys/changes` to behave sensibly when joined to a room with partial state. Signed-off-by: Sean Quah <seanq@matrix.org>
* Accept & store thread IDs for receipts (implement MSC3771). (#13782)Patrick Cloke2022-09-232-23/+66
| | | | Updates the `/receipts` endpoint and receipt EDU handler to parse a `thread_id` from the body and insert it in the database.
* Send device list updates out to servers in partially joined rooms (#13874)Sean Quah2022-09-232-1/+60
| | | | | | | | | | | Use the provided list of servers in the room from the `/send_join` response, since we will not know which users are in the room. This isn't sufficient to ensure that all remote servers receive the right device list updates, since the `/send_join` response may be inaccurate or we may calculate the membership state of new users in the room incorrectly. Signed-off-by: Sean Quah <seanq@matrix.org>
* Properly paginate forward in the /relations API. (#13840)Patrick Cloke2022-09-222-13/+31
| | | | | This fixes a bug where the `/relations` API with `dir=f` would skip the first item of each page (except the first page), causing incomplete data to be returned to the client.
* Track device IDs for pushers (#13831)Brendan Abolivier2022-09-212-2/+91
| | | Second half of the MSC3881 implementation
* Support enabling/disabling pushers (from MSC3881) (#13799)Brendan Abolivier2022-09-212-24/+61
| | | Partial implementation of MSC3881
* Add cache invalidation across workers to module API (#13667)Mathieu Velten2022-09-212-11/+32
| | | Signed-off-by: Mathieu Velten <mathieuv@matrix.org>
* Generate separate snapshots for logical databases (#13792)David Robertson2022-09-201-1/+4
| | | | | | | * Generate separate snapshots for sqlite, postgres and common * Cleanup postgres dbs in the TRAP * Say which logical DB we're applying updates to * Run background updates on the state DB * Add new option for accepting a SCHEMA_NUMBER
* Port the push rule classes to Rust. (#13768)Erik Johnston2022-09-201-8/+15
|
* Add support to purge rows from MSC2716 and other tables when purging a room ↵Eric Eastwood2022-09-163-0/+29
| | | | | | | | | | | (#13825) `event_failed_pull_attempts` added in https://github.com/matrix-org/synapse/pull/13589 MSC2716 related tables added in: - https://github.com/matrix-org/synapse/pull/10245/files#diff-3d42dfb44d02f7de3aada105e0bdc1cc9dd7f953cbf0f36c5d0f50827bf0320aR1 - Renamed in https://github.com/matrix-org/synapse/pull/10838/files#diff-2730bfbe9e688b55e46f9371aefe67dac2bd2b2b7d9d6b92774eea1fcfae156dR1 - https://github.com/matrix-org/synapse/pull/10498/files#diff-c52bbfbb5921a3f6f023b24343668479d966fac164f13b7c39d2197ce3afa7a5R1
* Support providing an index predicate for upserts. (#13822)Patrick Cloke2022-09-152-7/+24
| | | | This is useful to upsert against a table which has a unique partial index while avoiding conflicts.
* Keep track when we try and fail to process a pulled event (#13589)Eric Eastwood2022-09-144-9/+99
| | | | | | | | | | | | | | We can follow-up this PR with: 1. Only try to backfill from an event if we haven't tried recently -> https://github.com/matrix-org/synapse/issues/13622 1. When we decide to backfill that event again, process it in the background so it doesn't block and make `/messages` slow when we know it will probably fail again -> https://github.com/matrix-org/synapse/issues/13623 1. Generally track failures everywhere we try and fail to pull an event over federation -> https://github.com/matrix-org/synapse/issues/13700 Fix https://github.com/matrix-org/synapse/issues/13621 Part of https://github.com/matrix-org/synapse/issues/13356 Mentioned in [internal doc](https://docs.google.com/document/d/1lvUoVfYUiy6UaHB6Rb4HicjaJAU40-APue9Q4vzuW3c/edit#bookmark=id.qv7cj51sv9i5)
* Update event push action and receipt tables to support threads. (#13753)Patrick Cloke2022-09-148-6/+295
| | | | | | | | | | | | | | | Adds a `thread_id` column to the `event_push_actions`, `event_push_actions_staging`, and `event_push_summary` tables. This will notifications to be segmented by the thread in a future pull request. The `thread_id` column stores the root event ID or the special value `"main"`. The `thread_id` column for `event_push_actions` and `event_push_summary` is backfilled with `"main"` for all existing rows. New entries into `event_push_actions` and `event_push_actions_staging` will get the proper thread ID. `receipts_linearized` and `receipts_graph` also gain a `thread_id` column, which is similar, except `NULL` is a special value meaning the receipt is "unthreaded". See MSC3771 and MSC3773 for where this data will be useful.
* Use partial indices on SQLIte. (#13802)Patrick Cloke2022-09-143-5/+58
| | | | | | | Partial indices have been supported since SQLite 3.8, but Synapse now requires >= 3.27, so we can enable support for them. This requires rebuilding previous indices which were partial on PostgreSQL, but not on SQLite.
* Deduplicate `is_server_notices_room`. (#13780)reivilibre2022-09-141-0/+17
|
* Remove incorrect migration file from `state` logical DB (#13788)David Robertson2022-09-141-37/+0
| | | | | | | | | | | | | * Remove incorrect migration file from `state` logical DB The table `ex_outlier_stream` is part of the `main` logical DB; it should not have been created in the `state` logical DB. We remove this migration now as a tidy-up. Note: we cannot `DROP TABLE IF EXISTS ex_outlier_stream` in a new migration, because some (most) instances of Synapse host both of these logical DBs on the same DB cluster. * Changelog
* Fix bug in device list caching when remote users leave rooms (#13749)Sean Quah2022-09-141-3/+17
| | | | | | | | | | | | When a remote user leaves the last room shared with the homeserver, we have to mark their device list as unsubscribed, otherwise we would hold on to a stale device list in our cache. Crucially, the device list would remain cached even after the remote user rejoined the room, which could lead to E2EE failures until the next change to the remote user's device list. Fixes #13651. Signed-off-by: Sean Quah <seanq@matrix.org>
* Make sequence `cache_invalidation_stream_seq` begin at `2` (#13766)Mathieu Velten2022-09-132-0/+24
| | | | Signed-off-by: Mathieu Velten <mathieuv@matrix.org> Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
* Updates to the schema dump script (#13770)David Robertson2022-09-131-0/+4
|
* Add receipts event stream ordering (#13703)Nick Mills-Barrett2022-09-132-1/+92
|
* Remove check current state membership up to date (#13745)Nick Mills-Barrett2022-09-122-155/+99
| | | | | | | * Remove checks for membership column in current_state_events * Add schema script to force through the `current_state_events_membership` background job Contributed by Nick @ Beeper (@fizzadar).
* Use an upsert for `receipts_graph`. (#13752)Patrick Cloke2022-09-091-8/+4
| | | | | | Instead of a delete, then insert. This was previously done for `receipts_linearized` in 2dc430d36ef793b38d6d79ec8db4ea60588df2ee (#7607).
* Require SQLite >= 3.27.0 (#13760)David Robertson2022-09-097-207/+105
|
* Add timestamp to user's consent (#13741)Dirk Klimpel2022-09-082-1/+21
| | | Co-authored-by: reivilibre <olivier@librepush.net>
* Update docstrings to explain the impact of partial state (#13750)Sean Quah2022-09-081-1/+16
| | | | | | | Update the docstrings for `get_users_in_room` and `get_current_hosts_in_room` to explain the impact of partial state. Signed-off-by: Sean Quah <seanq@matrix.org>
* Avoid raising errors due to malformed IDs in `get_current_hosts_in_room` ↵Sean Quah2022-09-081-1/+4
| | | | | | | | | | (#13748) Handle malformed user IDs with no colons in `get_current_hosts_in_room`. It's not currently possible for a malformed user ID to join a room, so this error would never be hit. Signed-off-by: Sean Quah <seanq@matrix.org>
* Instrument `get_metadata_for_events` for tracing (#13730)Eric Eastwood2022-09-071-0/+2
| | | | When backfilling, `_get_state_ids_after_missing_prev_event` calls [`get_metadata_for_events`](https://github.com/matrix-org/synapse/blob/26bc26586b4b95d63ce7e453e9312469843f796e/synapse/handlers/federation_event.py#L1133). For `#matrix:matrix.org`, it's called with 77k `state_events` which means 77 calls to the database and takes 28 seconds.
* Cancel the processing of key query requests when they time out. (#13680)reivilibre2022-09-0710-1/+30
|
* Rename the `EventFormatVersions` enum values so that they line up with room ↵reivilibre2022-09-072-4/+4
| | | | version numbers. (#13706)
* Add a schema delta to drop unstable private read receipts. (#13692)Patrick Cloke2022-09-011-0/+19
| | | | Otherwise they'll be leaked due to the filtering code only respecting the stable identifiers for private read receipts.
* Cache `is_partial_state_room` (#13693)Erik Johnston2022-09-011-4/+7
| | | Fixes #13613.
* Remove support for unstable private read receipts (#13653)Šimon Brandner2022-09-011-2/+0
| | | Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
* Remove cached wrap on `_get_joined_users_from_context` method (#13569)Nick Mills-Barrett2022-08-311-84/+38
| | | | | | | The method doesn't actually do any data fetching and the method that does, `_get_joined_profile_from_event_id`, has its own cache. Signed off by Nick @ Beeper (@Fizzadar).
* Fix admin List Room API return type on sqlite (#13509)David Robertson2022-08-311-2/+4
|
* Give the correct next event when the message timestamps are the same - ↵Eric Eastwood2022-08-301-2/+10
| | | | | | | | | MSC3030 (#13658) Discovered while working on https://github.com/matrix-org/synapse/pull/13589 and I had all the messages at the same timestamp in the tests. Part of https://github.com/matrix-org/matrix-spec-proposals/pull/3030 Complement tests: https://github.com/matrix-org/complement/pull/457
* Drop unused column `application_services_state.last_txn` (#13627)Shay2022-08-303-0/+58
|
* Speed up inserting `event_push_actions_staging`. (#13634)Patrick Cloke2022-08-301-20/+8
| | | By using `execute_values` instead of `execute_batch`.
* Optimize how we calculate `likely_domains` during backfill (#13575)Eric Eastwood2022-08-302-19/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Optimize how we calculate `likely_domains` during backfill because I've seen this take 17s in production just to `get_current_state` which is used to `get_domains_from_state` (see case [*2. Loading tons of events* in the `/messages` investigation issue](https://github.com/matrix-org/synapse/issues/13356)). There are 3 ways we currently calculate hosts that are in the room: 1. `get_current_state` -> `get_domains_from_state` - Used in `backfill` to calculate `likely_domains` and `/timestamp_to_event` because it was cargo-culted from `backfill` - This one is being eliminated in favor of `get_current_hosts_in_room` in this PR 🕳 1. `get_current_hosts_in_room` - Used for other federation things like sending read receipts and typing indicators 1. `get_hosts_in_room_at_events` - Used when pushing out events over federation to other servers in the `_process_event_queue_loop` Fix https://github.com/matrix-org/synapse/issues/13626 Part of https://github.com/matrix-org/synapse/issues/13356 Mentioned in [internal doc](https://docs.google.com/document/d/1lvUoVfYUiy6UaHB6Rb4HicjaJAU40-APue9Q4vzuW3c/edit#bookmark=id.2tvwz3yhcafh) ### Query performance #### Before The query from `get_current_state` sucks just because we have to get all 80k events. And we see almost the exact same performance locally trying to get all of these events (16s vs 17s): ``` synapse=# SELECT type, state_key, event_id FROM current_state_events WHERE room_id = '!OGEhHVWSdvArJzumhm:matrix.org'; Time: 16035.612 ms (00:16.036) synapse=# SELECT type, state_key, event_id FROM current_state_events WHERE room_id = '!OGEhHVWSdvArJzumhm:matrix.org'; Time: 4243.237 ms (00:04.243) ``` But what about `get_current_hosts_in_room`: When there is 8M rows in the `current_state_events` table, the previous query in `get_current_hosts_in_room` took 13s from complete freshness (when the events were first added). But takes 930ms after a Postgres restart or 390ms if running back to back to back. ```sh $ psql synapse synapse=# \timing on synapse=# SELECT COUNT(DISTINCT substring(state_key FROM '@[^:]*:(.*)$')) FROM current_state_events WHERE type = 'm.room.member' AND membership = 'join' AND room_id = '!OGEhHVWSdvArJzumhm:matrix.org'; count ------- 4130 (1 row) Time: 13181.598 ms (00:13.182) synapse=# SELECT COUNT(*) from current_state_events where room_id = '!OGEhHVWSdvArJzumhm:matrix.org'; count ------- 80814 synapse=# SELECT COUNT(*) from current_state_events; count --------- 8162847 synapse=# SELECT pg_size_pretty( pg_total_relation_size('current_state_events') ); pg_size_pretty ---------------- 4702 MB ``` #### After I'm not sure how long it takes from complete freshness as I only really get that opportunity once (maybe restarting computer but that's cumbersome) and it's not really relevant to normal operating times. Maybe you get closer to the fresh times the more access variability there is so that Postgres caches aren't as exact. Update: The longest I've seen this run for is 6.4s and 4.5s after a computer restart. After a Postgres restart, it takes 330ms and running back to back takes 260ms. ```sh $ psql synapse synapse=# \timing on Timing is on. synapse=# SELECT substring(c.state_key FROM '@[^:]*:(.*)$') as host FROM current_state_events c /* Get the depth of the event from the events table */ INNER JOIN events AS e USING (event_id) WHERE c.type = 'm.room.member' AND c.membership = 'join' AND c.room_id = '!OGEhHVWSdvArJzumhm:matrix.org' GROUP BY host ORDER BY min(e.depth) ASC; Time: 333.800 ms ``` #### Going further To improve things further we could add a `limit` parameter to `get_current_hosts_in_room`. Realistically, we don't need 4k domains to choose from because there is no way we're going to query that many before we a) probably get an answer or b) we give up. Another thing we can do is optimize the query to use a index skip scan: - https://wiki.postgresql.org/wiki/Loose_indexscan - Index Skip Scan, https://commitfest.postgresql.org/37/1741/ - https://www.timescale.com/blog/how-we-made-distinct-queries-up-to-8000x-faster-on-postgresql/
* Directly lookup local membership instead of getting all members in a room ↵Eric Eastwood2022-08-241-0/+26
| | | | | first (`get_users_in_room` mis-use) (#13608) See https://github.com/matrix-org/synapse/pull/13575#discussion_r953023755
* When loading current ids, sort by `stream_id` to avoid incorrect overwrite ↵Eric Eastwood2022-08-241-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and avoid errors caused by sorting alphabetical instance name which can be `null` (#13585) When loading current ids, sort by stream ID so that we don't want to overwrite the `current_position` of an instance to a lower stream ID than we're actually at ([discussion](https://github.com/matrix-org/synapse/pull/13585#discussion_r951795379)). Previously, it sorted alphabetically by instance name which can be `null` and throw errors but more importantly, accomplishes nothing. Fixes the following startup error which is why I started looking into this area: ``` $ poetry run synapse_homeserver --config-path homeserver.yaml **************************************************************** Error during initialisation: '<' not supported between instances of 'NoneType' and 'str' There may be more information in the logs. **************************************************************** ``` Somehow my database ended up looking like the following, notice the `instance_name` is `null` in the db, and we can't sort `NoneType` things. Another question is why do we see the `instance_name` as `null` sometimes instead of `master` in monolith mode? ``` $ psql synapse synapse=# SELECT * FROM stream_positions; stream_name | instance_name | stream_id -----------------+---------------+----------- account_data | master | 1242 events | master | 1787 to_device | master | 58 presence_stream | master | 485638 receipts | master | 341 backfill | master | -139106 (6 rows) synapse=# SELECT instance_name, stream_id FROM receipts_linearized; instance_name | stream_id ---------------+----------- | 211 | 3 | 4 | 212 | 213 | 224 | 228 | 164 | 313 | 253 | 38 | 321 | 324 | 189 | 192 | 193 | 194 | 195 | 197 | 198 | 275 | 79 | 339 | 340 | 82 | 341 | 84 | 85 | 91 | 119 ```
* Rewrite get push actions queries (#13597)Nick Mills-Barrett2022-08-241-160/+68
|
* Fix regression caused by #13573 (#13600)Erik Johnston2022-08-231-4/+6
| | | Broke in #13573.
* Speed up fetching large numbers of push rules (#13592)Erik Johnston2022-08-232-8/+1
|
* Cache user IDs instead of profile objects (#13573)Nick Mills-Barrett2022-08-231-38/+29
| | | The profile objects are never used and increase cache size significantly.
* `synapse.api.auth.Auth` cleanup: make permission-related methods use ↵Quentin Gliech2022-08-221-1/+1
| | | | | | | | | `Requester` instead of the `UserID` (#13024) Part of #13019 This changes all the permission-related methods to rely on the Requester instead of the UserID. This is a first step towards enabling scoped access tokens at some point, since I expect the Requester to have scope-related informations in it. It also changes methods which figure out the user/device/appservice out of the access token to return a Requester instead of something else. This avoids having store-related objects in the methods signatures.
* Avoid blocking lazy-loading `/sync`s during partial joins (#13477)Sean Quah2022-08-181-4/+20
| | | | | | | | | | | | | | | | | Use a state filter or accept partial state in a few places where we request state, to avoid blocking. To make lazy-loading `/sync`s work, we need to provide the memberships of event senders, which are not guaranteed to be in the room state. Instead we dig through auth events for memberships to present to clients. The auth events of an event are guaranteed to contain a passable membership event, otherwise the event would have been rejected. Note that this only covers the common code paths encountered during testing. There has been no exhaustive checking of all sync code paths. Fixes #13146. Signed-off-by: Sean Quah <seanq@matrix.org>
* Fix a bug in the `/event_reports` Admin API which meant that the total count ↵reivilibre2022-08-171-0/+6
| | | | | could be larger than the number of results you can actually query for. (#13525) Co-authored-by: Brendan Abolivier <babolivier@matrix.org>
* Add forgotten status to Room Details API (#13503)Dirk Klimpel2022-08-171-0/+24
|
* Instrument the federation/backfill part of `/messages` (#13489)Eric Eastwood2022-08-166-14/+70
| | | | | | | | | Instrument the federation/backfill part of `/messages` so it's easier to follow what's going on in Jaeger when viewing a trace. Split out from https://github.com/matrix-org/synapse/pull/13440 Follow-up from https://github.com/matrix-org/synapse/pull/13368 Part of https://github.com/matrix-org/synapse/issues/13356
* Faster room joins: make `/joined_members` block whilst the room is partial ↵reivilibre2022-08-162-0/+16
| | | | stated. (#13514)
* Make push rules use proper structures. (#13522)Erik Johnston2022-08-162-69/+74
| | | | | | | | | | | | This improves load times for push rules: | Version | Time per user | Time for 1k users | | -------------------- | ------------- | ----------------- | | Before | 138 µs | 138ms | | Now (with custom) | 2.11 µs | 2.11ms | | Now (without custom) | 49.7 ns | 0.05 ms | This therefore has a large impact on send times for rooms with large numbers of local users in the room.
* Instrument `FederationStateIdsServlet` - `/state_ids` (#13499)Eric Eastwood2022-08-151-0/+3
| | | Instrument FederationStateIdsServlet - `/state_ids` so it's easier to follow what's going on in Jaeger when viewing a trace.
* Revert "Update locked versions of mypy and mypy-zope (#13521)"David Robertson2022-08-151-6/+16
| | | | | | | | This reverts commit f383b9b3eceaa082d5ae690550fe41460b711779. Other PRs were seeing mypy failures that looked to be related to mypy-zope. Confusingly, we didn't see this on #13521. Revert this for now and investigate later.
* Clarifications for event push action processing. (#13485)Patrick Cloke2022-08-152-21/+34
| | | | | | | | * Clarifies comments. * Fixes an erroneous comment (about return type) added in #13455 (ec24813220f9d54108924dc04aecd24555277b99). * Clarifies the name of a variable. * Simplifies logic of pulling out the latest join for the requesting user.
* Update locked versions of mypy and mypy-zope (#13521)David Robertson2022-08-151-16/+6
|
* Update the rejected state of events during resync (#13459)Richard van der Hoff2022-08-113-9/+65
| | | | | Events can be un-rejected or newly-rejected during resync, so ensure we update the database and caches when that happens.
* Support stable identifiers for MSC2285: private read receipts. (#13273)Šimon Brandner2022-08-051-15/+70
| | | | | This adds support for the stable identifiers of MSC2285 while continuing to support the unstable identifiers behind the configuration flag. These will be removed in a future version.
* Add comments about how event push actions are stored. (#13445)Erik Johnston2022-08-041-0/+61
|
* Improve comments (& avoid a duplicate query) in push actions processing. ↵Patrick Cloke2022-08-041-124/+158
| | | | | | | | | (#13455) * Adds docstrings and inline comments. * Formats SQL queries using triple quoted strings. * Minor formatting changes. * Avoid fetching `event_push_summary_stream_ordering` multiple times in the same transactions.
* Update type of `EventContext.rejected` (#13460)Richard van der Hoff2022-08-041-1/+1
|
* Optimise async get event lookups (#13435)Nick Mills-Barrett2022-08-042-8/+69
| | | | | | Still maintains local in memory lookup optimisation, but does any external lookup as part of the deferred that prevents duplicate lookups for the same event at once. This makes the assumption that fetching from an external cache is a non-zero load operation.
* Instrument `/messages` for understandable traces in Jaeger (#13368)Eric Eastwood2022-08-032-0/+7
| | | | | | In Jaeger: - Before: huge list of uncategorized database calls - After: nice and collapsible into units of work
* Refactor `_resolve_state_at_missing_prevs` to return an `EventContext` (#13404)Sean Quah2022-08-011-0/+4
| | | | | | | | Previously, `_resolve_state_at_missing_prevs` returned the resolved state before an event and a partial state flag. These were unwieldy to carry around would only ever be used to build an event context. Build the event context directly instead. Signed-off-by: Sean Quah <seanq@matrix.org>
* Faster joins: fix rejected events becoming un-rejected during resync (#13413)Richard van der Hoff2022-08-011-3/+5
| | | | | Make sure that we re-check the auth rules during state resync, otherwise rejected events get un-rejected.
* Use stable prefixes for MSC3827: filtering of `/publicRooms` by room type ↵Šimon Brandner2022-07-271-1/+1
| | | | | | (#13370) Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
* Fix infinite loop in partial-state resync (#13353)Richard van der Hoff2022-07-261-1/+19
| | | | | Make sure that we only pull out events from the db once they have no prev-events with partial state.
* Faster room joins: avoid blocking when pulling events with missing prevs ↵Sean Quah2022-07-261-2/+6
| | | | | | | | | (#13355) Avoid blocking on full state in `_resolve_state_at_missing_prevs` and return a new flag indicating whether the resolved state is partial. Thread that flag around so that it makes it into the event context. Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Remove unused argument for get_relations_for_event. (#13383)Patrick Cloke2022-07-261-6/+0
|
* Refactor presence so we can prune user in room caches (#13313)Erik Johnston2022-07-252-15/+72
| | | | | | | | See #10826 and #10786 for context as to why we had to disable pruning on those caches. Now that `get_users_who_share_room_with_user` is called frequently only for presence, we just need to make calls to it less frequent and then we can remove the various levels of caching that is going on.
* Make DictionaryCache have better expiry properties (#13292)Erik Johnston2022-07-211-1/+8
|
* Track DB txn times w/ two counters, not histogram (#13342)David Robertson2022-07-211-3/+5
|
* Add missing types to opentracing. (#13345)Patrick Cloke2022-07-213-6/+6
| | | After this change `synapse.logging` is fully typed.
* Use cache store remove base slaved (#13329)Nick Mills-Barrett2022-07-212-27/+28
| | | This comes from two identical definitions in each of the base stores, and means the base slaved store is now empty and can be removed.
* Update `get_pdu` to return the original, pristine `EventBase` (#13320)Eric Eastwood2022-07-201-3/+20
| | | | | | | | | | | | Update `get_pdu` to return the untouched, pristine `EventBase` as it was originally seen over federation (no metadata added). Previously, we returned the same `event` reference that we stored in the cache which downstream code modified in place and added metadata like setting it as an `outlier` and essentially poisoned our cache. Now we always return a copy of the `event` so the original can stay pristine in our cache and re-used for the next cache call. Split out from https://github.com/matrix-org/synapse/pull/13205 As discussed at: - https://github.com/matrix-org/synapse/pull/13205#discussion_r918365746 - https://github.com/matrix-org/synapse/pull/13205#discussion_r918366125 Related to https://github.com/matrix-org/synapse/issues/12584. This PR doesn't fix that issue because it hits [`get_event` which exists from the local database before it tries to `get_pdu`](https://github.com/matrix-org/synapse/blob/7864f33e286dec22368dc0b11c06eebb1462a51e/synapse/federation/federation_client.py#L581-L594).
* Add type annotations to `trace` decorator. (#13328)Patrick Cloke2022-07-192-7/+42
| | | | Functions that are decorated with `trace` are now properly typed and the type hints for them are fixed.
* Reduce memory usage of state group cache (#13323)Erik Johnston2022-07-191-1/+2
|
* Rate limit joins per-room (#13276)David Robertson2022-07-191-8/+14
|
* Safe async event cache (#13308)Nick Mills-Barrett2022-07-197-21/+101
| | | | | | | | Fix race conditions in the async cache invalidation logic, by separating the async & local invalidation calls and ensuring any async call i executed first. Signed off by Nick @ Beeper (@Fizzadar).
* Increase batch size of `bulk_get_push_rules` and ↵Shay2022-07-182-1/+2
| | | | `_get_joined_profiles_from_event_ids`. (#13300)
* Improve performance of query ` _get_subset_users_in_room_with_profiles` (#13299)Shay2022-07-181-1/+1
|
* Revert "Make all `process_replication_rows` methods async (#13304)" (#13312)Erik Johnston2022-07-188-21/+15
| | | This reverts commit 5d4028f217f178fcd384d5bfddd92225b4e78c51.
* Use READ COMMITTED isolation level when purging rooms (#12942)Nick Mills-Barrett2022-07-181-2/+31
| | | | | To close: #10294. Signed off by Nick @ Beeper.
* Make all `process_replication_rows` methods async (#13304)Nick Mills-Barrett2022-07-178-15/+21
| | | | | More prep work for asyncronous caching, also makes all process_replication_rows methods consistent (presence handler already is so). Signed off by Nick @ Beeper (@Fizzadar)
* Don't pull out the full state when storing state (#13274)Erik Johnston2022-07-152-54/+104
|
* Bg update to populate new `events` table columns (#13215)Richard van der Hoff2022-07-152-0/+134
| | | | | These columns were added back in Synapse 1.52, and have been populated for new events since then. It's now (beyond) time to back-populate them for existing events.
* Fix a bug which could lead to incorrect state (#13278)Erik Johnston2022-07-151-1/+2
| | | | | There are two fixes here: 1. A long-standing bug where we incorrectly calculated `delta_ids`; and 2. A bug introduced in #13267 where we got current state incorrect.
* Async get event cache prep (#13242)Nick Mills-Barrett2022-07-156-20/+41
| | | | | Some experimental prep work to enable external event caching based on #9379 & #12955. Doesn't actually move the cache at all, just lays the groundwork for async implemented caches. Signed off by Nick @ Beeper (@Fizzadar)
* Federation Sender & Appservice Pusher Stream Optimisations (#13251)Nick Mills-Barrett2022-07-153-71/+38
| | | | | | | | | | | | | * Replace `get_new_events_for_appservice` with `get_all_new_events_stream` The functions were near identical and this brings the AS worker closer to the way federation senders work which can allow for multiple workers to handle AS traffic. * Pull received TS alongside events when processing the stream This avoids an extra query -per event- when both federation sender and appservice pusher process events.
* Don't pull out state in `compute_event_context` for unconflicted state (#13267)Erik Johnston2022-07-143-30/+21
|
* Drop unused tables from groups/communities. (#12967)Patrick Cloke2022-07-132-3/+35
| | | | These tables have been unused since Synapse v1.61.0, although schema version 72 was added in Synapse v1.62.0.
* Drop unused table `event_reference_hashes` (#13218)Richard van der Hoff2022-07-121-0/+17
| | | This is unused since Synapse 1.60.0 (#12679). It's time for it to go.
* Log the stack when waiting for an entire room to be un-partial stated (#13257)Sean Quah2022-07-121-0/+1
| | | | The stack is already logged when waiting for an event to be un-partial stated. Log the stack for rooms as well, to aid in debugging.
* expose whether a room is a space in the Admin API (#13208)andrew do2022-07-121-2/+4
|
* Don't pull out the full state when calculating push actions (#13078)Erik Johnston2022-07-113-0/+107
|
* Remove delay when rotating event push actions (#13211)Erik Johnston2022-07-111-3/+1
| | | | We want to be as up to date as possible, and sleeping doesn't help here and can mean we fall behind.
* Fix notification count after a highlighted message (#13223)Erik Johnston2022-07-081-3/+8
| | | | | Fixes #13196 Broke by #13005
* Faster room joins: fix race in recalculation of current room state (#13151)Sean Quah2022-07-072-48/+107
| | | | | | | | | | | Bounce recalculation of current state to the correct event persister and move recalculation of current state into the event persistence queue, to avoid concurrent updates to a room's current state. Also give recalculation of a room's current state a real stream ordering. Signed-off-by: Sean Quah <seanq@matrix.org>
* Fix bug where we failed to delete old push actions (#13194)Erik Johnston2022-07-061-2/+4
| | | This happened if we encountered a stream ordering in `event_push_actions` that had more rows than the batch size of the delete, as If we don't delete any rows in an iteration then the next time round we get the exact same stream ordering and get stuck.
* Handle race between persisting an event and un-partial stating a room (#13100)Sean Quah2022-07-053-21/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Whenever we want to persist an event, we first compute an event context, which includes the state at the event and a flag indicating whether the state is partial. After a lot of processing, we finally try to store the event in the database, which can fail for partial state events when the containing room has been un-partial stated in the meantime. We detect the race as a foreign key constraint failure in the data store layer and turn it into a special `PartialStateConflictError` exception, which makes its way up to the method in which we computed the event context. To make things difficult, the exception needs to cross a replication request: `/fed_send_events` for events coming over federation and `/send_event` for events from clients. We transport the `PartialStateConflictError` as a `409 Conflict` over replication and turn `409`s back into `PartialStateConflictError`s on the worker making the request. All client events go through `EventCreationHandler.handle_new_client_event`, which is called in *a lot* of places. Instead of trying to update all the code which creates client events, we turn the `PartialStateConflictError` into a `429 Too Many Requests` in `EventCreationHandler.handle_new_client_event` and hope that clients take it as a hint to retry their request. On the federation event side, there are 7 places which compute event contexts. 4 of them use outlier event contexts: `FederationEventHandler._auth_and_persist_outliers_inner`, `FederationHandler.do_knock`, `FederationHandler.on_invite_request` and `FederationHandler.do_remotely_reject_invite`. These events won't have the partial state flag, so we do not need to do anything for then. The remaining 3 paths which create events are `FederationEventHandler.process_remote_join`, `FederationEventHandler.on_send_membership_event` and `FederationEventHandler._process_received_pdu`. We can't experience the race in `process_remote_join`, unless we're handling an additional join into a partial state room, which currently blocks, so we make no attempt to handle it correctly. `on_send_membership_event` is only called by `FederationServer._on_send_membership_event`, so we catch the `PartialStateConflictError` there and retry just once. `_process_received_pdu` is called by `on_receive_pdu` for incoming events and `_process_pulled_event` for backfill. The latter should never try to persist partial state events, so we ignore it. We catch the `PartialStateConflictError` in `on_receive_pdu` and retry just once. Refering to the graph of code paths in https://github.com/matrix-org/synapse/issues/12988#issuecomment-1156857648 may make the above make more sense. Signed-off-by: Sean Quah <seanq@matrix.org>
* Use upserts for updating `event_push_summary` (#13153)Erik Johnston2022-07-051-40/+7
|
* Merge tag 'v1.62.0rc3' into developAndrew Morgan2022-07-041-2/+7
|\ | | | | | | | | | | | | | | | | | | | | Synapse 1.62.0rc3 (2022-07-04) ============================== Bugfixes -------- - Update the version of the [ldap3 plugin](https://github.com/matrix-org/matrix-synapse-ldap3/) included in the `matrixdotorg/synapse` DockerHub images and the Debian packages hosted on `packages.matrix.org` to 0.2.1. This fixes [a bug](https://github.com/matrix-org/matrix-synapse-ldap3/pull/163) with usernames containing uppercase characters. ([\#13156](https://github.com/matrix-org/synapse/issues/13156)) - Fix a bug introduced in Synapse 1.62.0rc1 affecting unread counts for users on small servers. ([\#13168](https://github.com/matrix-org/synapse/issues/13168))
| * Fix stuck notification counts on small servers (#13168)Erik Johnston2022-07-041-2/+7
| |
* | Merge remote-tracking branch 'origin/release-v1.62' into developPatrick Cloke2022-06-302-22/+55
|\|
| * Fix unread counts on large servers (#13140)Erik Johnston2022-06-301-22/+26
| |
| * Add index to help delete old push actions (#13141)Erik Johnston2022-06-302-0/+29
| |
* | Don't actually one-line the SQL statements we send to the DB (#13129)Brendan Abolivier2022-06-301-3/+4
| |
* | Implement MSC3827: Filtering of `/publicRooms` by room type (#13031)Šimon Brandner2022-06-293-7/+148
| | | | | | | | Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
* | Improve performance of getting unread counts in rooms (#13119)Erik Johnston2022-06-293-4/+34
|/
* Fix serialization errors when rotating notifications (#13118)Erik Johnston2022-06-283-78/+171
|
* Fix type error that made its way onto develop (#13098)reivilibre2022-06-171-2/+2
| | | | | | | * Fix type error introduced accidentally by #13045 * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
* Rotate notifications more frequently (#13096)Erik Johnston2022-06-171-1/+1
|
* Use new `device_list_changes_in_room` table when getting device list changes ↵Erik Johnston2022-06-171-0/+59
| | | | (#13045)
* Add desc to `get_earliest_token_for_stats` (#13085)Erik Johnston2022-06-161-0/+1
|
* Type annotations in `synapse.databases.main.devices` (#13025)David Robertson2022-06-152-18/+34
| | | Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
* Speed up `get_unread_event_push_actions_by_room` (#13005)Erik Johnston2022-06-157-108/+256
| | | | | | | | | | | Fixes #11887 hopefully. The core change here is that `event_push_summary` now holds a summary of counts up until a much more recent point, meaning that the range of rows we need to count in `event_push_actions` is much smaller. This needs two major changes: 1. When we get a receipt we need to recalculate `event_push_summary` rather than just delete it 2. The logic for deleting `event_push_actions` is now divorced from calculating `event_push_summary`. In future it would be good to calculate `event_push_summary` while we persist a new event (it should just be a case of adding one to the relevant rows in `event_push_summary`), as that will further simplify the get counts logic and remove the need for us to periodically update `event_push_summary` in a background job.
* Clean up schema for `event_edges` (#12893)Richard van der Hoff2022-06-156-11/+215
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Remove redundant references to `event_edges.room_id` We don't need to care about the room_id here, because we are already checking the event id. * Clean up the event_edges table We make a number of changes to `event_edges`: * We give the `room_id` and `is_state` columns defaults (null and false respectively) so that we can stop populating them. * We drop any rows that have `is_state` set true - they should no longer exist. * We drop any rows that do not exist in `events` - these should not exist either. * We drop the old unique constraint on all the colums, which wasn't much use. * We create a new unique index on `(event_id, prev_event_id)`. * We add a foreign key constraint to `events`. These happen rather differently depending on whether we are on Postgres or SQLite. For SQLite, we just rebuild the whole table, copying only the rows we want to keep. For Postgres, we try to do things in the background as much as possible. * Stop populating `event_edges.room_id` and `is_state` We can just rely on the defaults.
* Rename delta to apply in the proper schema version. (#13050)Patrick Cloke2022-06-141-0/+0
|
* Replace noop background updates with DELETE. (#12954)Patrick Cloke2022-06-1311-116/+61
| | | | Removes the `register_noop_background_update` and deletes the background updates directly in a delta file.
* Faster joins: add issue links to the TODOs (#13004)Richard van der Hoff2022-06-095-1/+11
| | | | ... to help us keep track of these things
* Use READ COMMITTED isolation level when inserting read receipts (#12957)Nick Mills-Barrett2022-06-091-0/+5
|
* Use dummy fallback engines if imports fail (#12979)David Robertson2022-06-074-21/+46
|
* Fix a stale comment in get_room_version_id_txn. (#12969)Patrick Cloke2022-06-071-6/+1
|
* Consolidate the logic of delete_device/delete_devices. (#12970)Patrick Cloke2022-06-071-10/+0
| | | | | | | | By always using delete_devices and sometimes passing a list with a single device ID. Previously these methods had gotten out of sync with each other and it seems there's little benefit to the single-device variant.
* Prevent breaking old sqlite's when media retention is enabled (#12977)Andrew Morgan2022-06-071-1/+1
|
* Prevent local quarantined media from being claimed by media retention (#12972)Andrew Morgan2022-06-071-5/+63
|
* Remove remaining pieces of groups code. (#12966)Patrick Cloke2022-06-064-125/+3
| | | | | * Remove an unused stream ID generator. * Remove the now unused remote profile cache.
* Reduce state pulled from DB due to sending typing and receipts over ↵Erik Johnston2022-06-063-0/+46
| | | | | federation (#12964) Reducing the amount of state we pull from the DB is useful as fetching state is expensive in terms of DB, CPU and memory.
* Reduce the amount of state we pull from the DB (#12811)Erik Johnston2022-06-061-0/+27
|
* Remove groups code from synapse_port_db. (#12899)Patrick Cloke2022-06-031-7/+2
|
* Wait for lazy join to complete when getting current state (#12872)Erik Johnston2022-06-019-39/+207
|
* Remove remaining bits of groups code. (#12936)Patrick Cloke2022-06-011-4/+0
| | | | | | * Update worker docs to remove group endpoints. * Removes an unused parameter to `ApplicationService`. * Break dependency between media repo and groups. * Avoid copying `m.room.related_groups` state events during room upgrades.
* Fix 404 on `/sync` when the last event is a redaction of an unknown/purged ↵Richard van der Hoff2022-06-012-10/+14
| | | | | | | | | | | event (#12905) Currently, we try to pull the event corresponding to a sync token from the database. However, when we fetch redaction events, we check the target of that redaction (because we aren't allowed to send redactions to clients without validating them). So, if the sync token points to a redaction of an event that we don't have, we have a problem. It turns out we don't really need that event, and can just work with its ID and metadata, which sidesteps the whole problem.
* Remove most groups datastore code. (#12895)Patrick Cloke2022-05-311-1394/+4
| | | | The remaining piece is a background update that is needed for backwards compatibility.
* Faster room joins: Resume state re-syncing after a Synapse restart (#12813)Sean Quah2022-05-311-0/+27
| | | | Signed-off-by: Sean Quah <seanq@matrix.org>
* Reduce DB load of /sync when using presence (#12885)Erik Johnston2022-05-311-27/+48
| | | While the query was fast, we were calling it *a lot*.
* Stop reading from `event_edges.room_id`. (#12914)Richard van der Hoff2022-05-313-24/+21
| | | event_edges.room_id is implied by the event id, so there is no need to join on the room id.
* Rename storage classes (#12913)Erik Johnston2022-05-316-350/+406
|
* Add a migration step to cleanup potential leftovers of bug 11833 (#12784)Mathieu Velten2022-05-301-0/+19
| | | Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
* Fix invite notifications for users without pushers (#12840)DeepBlueV7.X2022-05-301-6/+0
| | | | Signed-off-by: Nicolas Werner <nicolas.werner@hotmail.de> Co-authored-by: Brendan Abolivier <github@brendanabolivier.com>
* Fix `get_metadata_for_events` (#12904)Richard van der Hoff2022-05-301-2/+2
| | | | This method was introduced in #12852. It is using the `state_key` column from the `events` table, which is not (yet) reliable (see #11496).
* Mutual rooms: Remove dependency on user directory (#12836)Jonathan de Jong2022-05-302-43/+24
|
* LockStore: fix acquiring a lock via `LockStore.try_acquire_lock` (#12832)Sumner Evans2022-05-301-1/+18
| | | Signed-off-by: Sumner Evans <sumner@beeper.com>
* Add a background job to automatically delete stale devices (#12855)Brendan Abolivier2022-05-271-0/+39
| | | Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
* Clean-up some receipts code (#12888)Patrick Cloke2022-05-271-42/+47
| | | | | * Properly marks private methods as private. * Adds missing docstrings. * Rework inline methods.
* Additional constants for EDU types. (#12884)Patrick Cloke2022-05-272-6/+7
| | | Instead of hard-coding strings in many places.
* Add storage and module API methods to get monthly active users and their ↵Matt C2022-05-271-0/+45
| | | | appservices (#12838)
* Fix room deletion (#12889)Richard van der Hoff2022-05-271-9/+10
| | | | | | | | | * Fix room deletion ae7858f broke room deletion by attempting to delete the entry from `rooms` before the tables that reference it. * faster_joins: remove database rows on purge
* Refactor have_seen_events to reduce OOMs (#12886)Richard van der Hoff2022-05-271-18/+24
| | | | | My server is currently OOMing in the middle of have_seen_events, so let's try to fix that.