summary refs log tree commit diff
path: root/synapse/storage (follow)
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Fix ambiguous column name that would prevent use of MSC2716 History Import ↵reivilibre2022-05-261-1/+1
| | | | when using Postgres as a database. (#12843)
* Avoid attempting to delete push actions for remote users. (#12879)Patrick Cloke2022-05-263-3/+6
| | | | Remote users will never have push actions, so we can avoid a database round-trip/transaction completely.
* Pull out less state when handling gaps mk2 (#12852)Erik Johnston2022-05-261-0/+59
|
* Fix caching behavior for relations push rules. (#12859)Patrick Cloke2022-05-251-2/+3
| | | | | By always returning all requested values from the function wrapped by cachedList. Otherwise implicit None values get added into the cache, which are unexpected.
* Misc clean-up of push rules datastore (#12856)Patrick Cloke2022-05-251-11/+5
|
* Fixes to MSC3787 implementation (#12858)David Robertson2022-05-241-18/+17
|
* Experimental support for MSC3772 (#12740)Patrick Cloke2022-05-243-0/+66
| | | | | | | | | | Implements the following behind an experimental configuration flag: * A new push rule kind for mutually related events. * A new default push rule (`.m.rule.thread_reply`) under an unstable prefix. This is missing part of MSC3772: * The `.m.rule.thread_reply_to_me` push rule, this depends on MSC3664 / #11804.
* Prevent expired events from being filtered out when retention is disabled ↵Brendan Abolivier2022-05-231-20/+25
| | | | | | (#12611) Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
* Fix media thumbnails being unusable before the index had been added in the ↵reivilibre2022-05-231-0/+2
| | | | background. (#12823)
* Update EventContext `get_current_event_ids` and `get_prev_event_ids` to ↵Shay2022-05-201-2/+5
| | | | accept state filters and update calls where possible (#12791)
* Add a unique index to `state_group_edges` to prevent duplicates being ↵reivilibre2022-05-193-0/+48
| | | | accidentally introduced and the consequential impact to performance. (#12687)
* Skip waiting for full state if a StateFilter does not require it (#12498)Richard van der Hoff2022-05-181-4/+59
| | | | | If `StateFilter` specifies a state set which we will have regardless of state-syncing, then we may as well return it immediately.
* Refactor `resolve_state_groups_for_events` to not pull out full state when ↵Shay2022-05-182-7/+7
| | | | no state resolution happens. (#12775)
* Add some type hints to `event_federation` datastore (#12753)Dirk Klimpel2022-05-181-64/+123
| | | Co-authored-by: David Robertson <david.m.robertson1@gmail.com>
* Do not keep going if there are 5 back-to-back background update failures. ↵reivilibre2022-05-181-0/+8
| | | | (#12781)
* Discard null-containing strings before updating the user directory (#12762)David Robertson2022-05-182-8/+5
|
* Move methods that call add_push_rule to PushRuleStore (#12772)Adam2022-05-181-51/+51
| | | Signed-off-by: Adam Roddick <ajroddick@tuta.io>
* Delete events from federation_inbound_events_staging table on purge (#12770)Mathieu Velten2022-05-171-0/+1
|
* allow `on_invalidate=None` in `@cached` methods (#12769)David Robertson2022-05-171-1/+2
|
* Add some type hints to datastore (#12717)Dirk Klimpel2022-05-174-145/+229
|
* Remove code which updates `application_services_state.last_txn` (#12680)Richard van der Hoff2022-05-172-24/+28
| | | | This column is unused as of #12209, so let's stop writing to it.
* Merge branch 'master' into developDavid Robertson2022-05-171-1/+1
|\
| * Fix query performance for /sync (#12745)Erik Johnston2022-05-161-1/+1
| |
* | Add index to cache invalidations (#12747)Erik Johnston2022-05-172-0/+26
| | | | | | | | | | For workers that rarely write to the cache the `get_all_updated_caches` query can become expensive if the worker falls behind when reading the cache.
* | Track in memory events using weakrefs (#10533)Erik Johnston2022-05-171-2/+33
| |
* | Tidy up and type-hint the database engine modules (#12734)David Robertson2022-05-175-94/+178
| | | | | | Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
* | Add `StreamKeyType` class and replace string literals with constants (#12567)Andrew Morgan2022-05-162-4/+6
| |
* | Merge tag 'v1.59.0rc2' into developDavid Robertson2022-05-161-8/+11
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Synapse 1.59.0rc2 (2022-05-16) ============================== Synapse 1.59 makes several changes that server administrators should be aware of: - Device name lookup over federation is now disabled by default. ([\#12616](https://github.com/matrix-org/synapse/issues/12616)) - The `synapse.app.appservice` and `synapse.app.user_dir` worker application types are now deprecated. ([\#12452](https://github.com/matrix-org/synapse/issues/12452), [\#12654](https://github.com/matrix-org/synapse/issues/12654)) See [the upgrade notes](https://github.com/matrix-org/synapse/blob/develop/docs/upgrade.md#upgrading-to-v1590) for more details. Additionally, this release removes the non-standard `m.login.jwt` login type from Synapse. It can be replaced with `org.matrix.login.jwt` for identical behaviour. This is only used if `jwt_config.enabled` is set to `true` in the configuration. ([\#12597](https://github.com/matrix-org/synapse/issues/12597)) Bugfixes -------- - Fix a bug introduced in Synapse 1.58.0 where `/sync` would fail if the most recent event in a room was rejected. ([\#12729](https://github.com/matrix-org/synapse/issues/12729))
| * Fix bug /sync returning 404 (#12729)Erik Johnston2022-05-161-8/+11
| | | | | | | | | | * Fix bug /sync returning 404 Fixes #12571
* | Consolidate logic for parsing relations. (#12693)Patrick Cloke2022-05-161-28/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | Parse the `m.relates_to` event content field (which describes relations) in a single place, this is used during: * Event persistence. * Validation of the Client-Server API. * Fetching bundled aggregations. * Processing of push rules. Each of these separately implement the logic and each made slightly different assumptions about what was valid. Some had minor / potential bugs.
* | Another batch of type annotations (#12726)David Robertson2022-05-131-5/+14
| |
* | Reduce the number of "untyped defs" (#12716)David Robertson2022-05-127-39/+76
| |
* | Fix `/messages` throwing a 500 when querying for non-existent room (#12683)Eric Eastwood2022-05-101-15/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix https://github.com/matrix-org/synapse/issues/12678 Complement test added: https://github.com/matrix-org/complement/pull/369 **Before:** 500 internal server error **After:** According to the [spec](https://spec.matrix.org/latest/client-server-api/#get_matrixclientv3roomsroomidmessages), calling `/messages` against a non-existent `room_id` should throw a 403 forbidden (since you're not part of the room). This also matches the behavior before https://github.com/matrix-org/synapse/pull/12370 which regressed Synapse to the 500 behavior. ```json { "errcode": "M_FORBIDDEN", "error": "User @test:my.synapse.server not in room !dne:my.synapse.server, and room previews are disabled" } ```
* | Refactor `EventContext` (#12689)Erik Johnston2022-05-102-41/+7
| | | | | | | | | | | | | | | | | | | | Refactor how the `EventContext` class works, with the intention of reducing the amount of state we fetch from the DB during event processing. The idea here is to get rid of the cached `current_state_ids` and `prev_state_ids` that live in the `EventContext`, and instead defer straight to the database (and its caching). One change that may have a noticeable effect is that we now no longer prefill the `get_current_state_ids` cache on a state change. However, that query is relatively light, since its just a case of reading a table from the DB (unlike fetching state at an event which is more heavyweight). For deployments with workers this cache isn't even used. Part of #12684
* | Add some type hints to datastore. (#12477)Dirk Klimpel2022-05-102-70/+119
| |
* | Stop writing to `event_reference_hashes` (#12679)Richard van der Hoff2022-05-103-29/+4
|/ | | | | This table is never read, since #11794. We stop writing to it; in future we can drop it altogether.
* Implement MSC3786: Add a default push rule to ignore m.room.server_acl ↵Šimon Brandner2022-05-101-11/+37
| | | | | | events (#12601) Fixes vector-im/element-web#20788 Implements matrix-org/matrix-spec-proposals#3786
* Use `ParamSpec` in a few places (#12667)David Robertson2022-05-092-13/+26
|
* Use `Concatenate` to annotate `do_execute` (#12666)David Robertson2022-05-091-5/+14
|
* Remove unused receipt datastore methods. (#12632)Patrick Cloke2022-05-051-54/+0
| | | The last usage was removed in 5a1dd297c3ce105a7f516d9d9fe87b94b9d356c8 (#8059).
* Add `mau_appservice_trial_days` config (#12619)Will Hunt2022-05-041-2/+6
| | | | | | | | | | | | | | | | | | | | | * Add mau_appservice_trial_days * Add a test * Tweaks * changelog * Ensure we sync after the delay * Fix types * Add config statement * Fix test * Reinstate logging that got removed * Fix feature name
* Implement changes to MSC2285 (hidden read receipts) (#12168)Šimon Brandner2022-05-041-32/+110
| | | | | * Changes hidden read receipts to be a separate receipt type (instead of a field on `m.read`). * Updates the `/receipts` endpoint to accept `m.fully_read`.
* Include bundled aggregations for the latest event in a thread. (#12273)Patrick Cloke2022-05-041-8/+3
| | | | | | The `latest_event` field of the bundled aggregations for `m.thread` relations did not include bundled aggregations itself. This resulted in clients needing to immediately request the event from the server (and thus making it useless that the latest event itself was serialized instead of just including an event ID).
* remove constantly lib use and switch to enums. (#12624)andrew do2022-05-044-28/+28
|
* Add a consistency check on events read from the database (#12620)Richard van der Hoff2022-05-031-0/+12
| | | | | | | I've seen a few errors which can only plausibly be explained by the calculated event id for an event being different from the ID of the event in the database. It should be cheap to check this, so let's do so and raise an exception.
* Fix race when persisting an event and deleting a room (#12594)Erik Johnston2022-05-032-2/+21
| | | | | This works by taking a row level lock on the `rooms` table at the start of both transactions, ensuring that they don't run at the same time. In the event persistence transaction we also check that there is an entry still in the `rooms` table. I can't figure out how to do this in SQLite. I was just going to lock the table, but it seems that we don't support that in SQLite either, so I'm *really* confused as to how we maintain integrity in SQLite when using `lock_table`....
* Improve the docstrings for the receipts store. (#12581)Patrick Cloke2022-04-281-5/+51
|
* Add a module API to allow modules to edit push rule actions (#12406)Brendan Abolivier2022-04-271-8/+7
| | | Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Remove unused `# type: ignore`s (#12531)David Robertson2022-04-272-5/+5
| | | | | | | | | | | | | | | | | | | | | | Over time we've begun to use newer versions of mypy, typeshed, stub packages---and of course we've improved our own annotations. This makes some type ignore comments no longer necessary. I have removed them. There was one exception: a module that imports `select.epoll`. The ignore is redundant on Linux, but I've kept it ignored for those of us who work on the source tree using not-Linux. (#11771) I'm more interested in the config line which enforces this. I want unused ignores to be reported, because I think it's useful feedback when annotating to know when you've fixed a problem you had to previously ignore. * Installing extras before typechecking Lacking an easy way to install all extras generically, let's bite the bullet and make install the hand-maintained `all` extra before typechecking. Now that https://github.com/matrix-org/backend-meta/pull/6 is merged to the release/v1 branch.
* Consistently use collections.abc.Mapping to check frozendict. (#12564)Patrick Cloke2022-04-271-3/+2
|
* Add some type hints to datastore (#12485)Dirk Klimpel2022-04-2711-84/+187
|
* Mark remote device list updates as already handled (#12557)Erik Johnston2022-04-261-1/+2
|
* Fix sending opentracing contexts to remote servers (#12555)Erik Johnston2022-04-261-1/+11
|
* Optimise backfill calculation (#12522)Richard van der Hoff2022-04-261-16/+14
| | | | | | Try to avoid an OOM by checking fewer extremities. Generally this is a big rewrite of _maybe_backfill, to try and fix some of the TODOs and other problems in it. It's best reviewed commit-by-commit.
* Handle cancellation in `EventsWorkerStore._get_events_from_cache_or_db` (#12529)Sean Quah2022-04-251-34/+49
| | | | | | | | Multiple calls to `EventsWorkerStore._get_events_from_cache_or_db` can reuse the same database fetch, which is initiated by the first call. Ensure that cancelling the first call doesn't cancel the other calls sharing the same database fetch. Signed-off-by: Sean Quah <seanq@element.io>
* Update `delay_cancellation` to accept any awaitable (#12468)Sean Quah2022-04-221-2/+1
| | | | | | | | This will mainly be useful when dealing with module callbacks, which are all typed as returning `Awaitable`s instead of coroutines or `Deferred`s. Signed-off-by: Sean Quah <seanq@element.io>
* Await un-partial-stating after a partial-state join (#12399)Richard van der Hoff2022-04-214-4/+155
| | | | | | When we join a room via the faster-joins mechanism, we end up with "partial state" at some points on the event DAG. Many parts of the codebase need to wait for the full state to load. So, we implement a mechanism to keep track of which events have partial state, and wait for them to be fully-populated.
* Implement MSC2815: allow room moderators to view redacted event content (#12427)Tulir Asokan2022-04-201-0/+18
| | | | | | Implements matrix-org/matrix-spec-proposals#2815 Signed-off-by: Tulir Asokan <tulir@maunium.net>
* Fix returned count of delete extremities admin API (#12496)Erik Johnston2022-04-191-3/+5
|
* Fix grammatical error in error message (#12483)Travis Ralston2022-04-181-1/+1
| | | | | * Fix grammatical error in error message * changelog
* Only send out device list updates for our own users (#12465)Erik Johnston2022-04-141-1/+3
| | | Broke in #12365
* Fix missing sync events during historical batch imports (#12319)Nick Mills-Barrett2022-04-131-0/+26
| | | | | | | | Discovered after much in-depth investigation in #12281. Closes: #12281 Closes: #3305 Signed off by: Nick Mills-Barrett nick@beeper.com
* Process device list updates asynchronously (#12365)Erik Johnston2022-04-122-55/+12
|
* Resync state after partial-state join (#12394)Richard van der Hoff2022-04-125-0/+174
| | | | | We work through all the events with partial state, updating the state at each of them. Once it's done, we recalculate the state for the whole room, and then mark the room as having complete state.
* Remove references to unstable identifiers from MSC3440. (#12382)Patrick Cloke2022-04-122-66/+17
| | | | | Removes references to unstable thread relation, unstable identifiers for filtering parameters, and the experimental config flag.
* Add some type hints to datastore (#12423)Dirk Klimpel2022-04-127-75/+120
| | | | | | | | | | | | | | | | | | | * Add some type hints to datastore * newsfile * change `Collection` to `List` * refactor return type of `select_users_txn` * correct type hint in `stream.py` * Remove `Optional` in `select_users_txn` * remove not needed return type in `__init__` * Revert change in `get_stream_id_for_event_txn` * Remove import from `Literal`
* Do not consider events by ignored users for bundled aggregations (#12235)Patrick Cloke2022-04-111-9/+143
| | | | | | | Consider the requester's ignored users when calculating the bundled aggregations. See #12285 / 4df10d32148ae29f792afc68ff774bcbd1915cea for corresponding changes for the `/relations` endpoint.
* Disallow untyped defs in synapse._scripts (#12422)David Robertson2022-04-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Of note: * No untyped defs in `register_new_matrix_user` This one might be contraversial. `request_registration` has three dependency-injection arguments used for testing. I'm removing the injection of the `requests` module and using `unitest.mock.patch` in the test cases instead. Doing `reveal_type(requests)` and `reveal_type(requests.get)` before the change: ``` synapse/_scripts/register_new_matrix_user.py:45: note: Revealed type is "Any" synapse/_scripts/register_new_matrix_user.py:46: note: Revealed type is "Any" ``` And after: ``` synapse/_scripts/register_new_matrix_user.py:44: note: Revealed type is "types.ModuleType" synapse/_scripts/register_new_matrix_user.py:45: note: Revealed type is "def (url: Union[builtins.str, builtins.bytes], params: Union[Union[_typeshed.SupportsItems[Union[builtins.str, builtins.bytes, builtins.int, builtins.float], Union[builtins.str, builtins.bytes, builtins.int, builtins.float, typing.Iterable[Union[builtins.str, builtins.bytes, builtins.int, builtins.float]], None]], Tuple[Union[builtins.str, builtins.bytes, builtins.int, builtins.float], Union[builtins.str, builtins.bytes, builtins.int, builtins.float, typing.Iterable[Union[builtins.str, builtins.bytes, builtins.int, builtins.float]], None]], typing.Iterable[Tuple[Union[builtins.str, builtins.bytes, builtins.int, builtins.float], Union[builtins.str, builtins.bytes, builtins.int, builtins.float, typing.Iterable[Union[builtins.str, builtins.bytes, builtins.int, builtins.float]], None]]], builtins.str, builtins.bytes], None] =, data: Union[Any, None] =, headers: Union[Any, None] =, cookies: Union[Any, None] =, files: Union[Any, None] =, auth: Union[Any, None] =, timeout: Union[Any, None] =, allow_redirects: builtins.bool =, proxies: Union[Any, None] =, hooks: Union[Any, None] =, stream: Union[Any, None] =, verify: Union[Any, None] =, cert: Union[Any, None] =, json: Union[Any, None] =) -> requests.models.Response" ``` * Drive-by comment in `synapse.storage.types` * No untyped defs in `synapse_port_db` This was by far the most painful. I'm happy to break this up into smaller pieces for review if it's not managable as-is.
* Optimise `_update_client_ips_batch_txn` to batch together database ↵reivilibre2022-04-082-35/+132
| | | | | operations. (#12252) Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
* Fix `synapse_event_persisted_position` metric (#12390)Richard van der Hoff2022-04-061-3/+3
| | | | Fixes a bug introduced in #11417 where we would only included backfilled events in `synapse_event_persisted_position`
* Update type annotations for compatiblity with prometheus_client 0.14 (#12389)Richard van der Hoff2022-04-061-3/+1
| | | | | | | Principally, `prometheus_client.REGISTRY.register` now requires its argument to extend `prometheus_client.Collector`. Additionally, `Gauge.set` is now annotated so that passing `Optional[int]` causes an error.
* Generate historic pagination token for `/messages` when no `?from` token ↵Eric Eastwood2022-04-061-9/+11
| | | | provided (#12370)
* Refactor and convert `Linearizer` to async (#12357)Sean Quah2022-04-051-1/+1
| | | | | | | | | | | Refactor and convert `Linearizer` to async. This makes a `Linearizer` cancellation bug easier to fix. Also refactor to use an async context manager, which eliminates an unlikely footgun where code that doesn't immediately use the context manager could forget to release the lock. Signed-off-by: Sean Quah <seanq@element.io>
* Prefill more stream change caches. (#12372)Erik Johnston2022-04-054-38/+89
|
* Prefill the device_list_stream_cache (#12367)Erik Johnston2022-04-041-1/+11
| | | | | | | * Prefill the device_list_stream_cache * Newsfile * Newsfile
* Track device list updates per room. (#12321)Erik Johnston2022-04-044-25/+232
| | | | | | | | | | | | | | This is a first step in dealing with #7721. The idea is basically that rather than calculating the full set of users a device list update needs to be sent to up front, we instead simply record the rooms the user was in at the time of the change. This will allow a few things: 1. we can defer calculating the set of remote servers that need to be poked about the change; and 2. during `/sync` and `/keys/changes` we can avoid also avoid calculating users who share rooms with other users, and instead just look at the rooms that have changed. However, care needs to be taken to correctly handle server downgrades. As such this PR writes to both `device_lists_changes_in_room` and the `device_lists_outbound_pokes` table synchronously. In a future release we can then bump the database schema compat version to `69` and then we can assume that the new `device_lists_changes_in_room` exists and is handled. There is a temporary option to disable writing to `device_lists_outbound_pokes` synchronously, allowing us to test the new code path does work (and by implication upgrading to a future release and downgrading to this one will work correctly). Note: Ideally we'd do the calculation of room to servers on a worker (e.g. the background worker), but currently only master can write to the `device_list_outbound_pokes` table.
* Use a sequence to generate AS transaction IDs, drop `last_txn` AS state (#12209)Nick Mills-Barrett2022-04-013-44/+67
| | | | | | | | Switching to a sequence means there's no need to track `last_txn` on the AS state table to generate new TXN IDs. This also means that there is no longer contention between the AS scheduler and AS handler on updates to the `application_services_state` table, which will prevent serialization errors during the complete AS txn transaction.
* Move `update_client_ip` background job from the main process to the ↵reivilibre2022-04-014-76/+117
| | | | background worker. (#12251)
* Raise an exception when getting state at an outlier (#12191)Richard van der Hoff2022-04-012-4/+32
| | | | | | It seems like calling `_get_state_group_for_events` for an event where the state is unknown is an error. Accordingly, let's raise an exception rather than silently returning an empty result.
* Optimise `_get_state_after_missing_prev_event`: use `/state` (#12040)Richard van der Hoff2022-04-011-5/+3
| | | If we're missing most of the events in the room state, then we may as well call the /state endpoint, instead of individually requesting each and every event.
* Add more type hints to the main state store. (#12267)Patrick Cloke2022-03-311-7/+11
|
* Remove an unnecessary class from the relations code. (#12338)Patrick Cloke2022-03-312-62/+8
| | | | | The PaginationChunk class attempted to bundle some properties together, but really just caused callers to jump through hoops and hid implementation details.
* Remove the unused and unstable `/aggregations` endpoint. (#12293)Patrick Cloke2022-03-302-97/+14
| | | | | | | | | This endpoint was removed from MSC2675 before it was approved. It is currently unspecified (even in any MSCs) and therefore subject to removal. It is not implemented by any known clients. This also changes the bundled aggregation format for `m.annotation`, which previously included pagination tokens for the `/aggregations` endpoint, which are no longer useful.
* Send device list updates to application services (MSC3202) - part 1 (#11881)Andrew Morgan2022-03-303-18/+67
| | | Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
* Start application service stream token tracking from 1 (#12193)Andrew Morgan2022-03-301-1/+2
| | | Co-authored-by: Erik Johnston <erik@matrix.org>
* Add a configuration to exclude rooms from sync response (#12310)Brendan Abolivier2022-03-302-15/+36
|
* Update `LoggingTransaction.call_after` and `call_on_exception` docstrings ↵Sean Quah2022-03-291-3/+20
| | | | | | | | (#12315) Document the behaviour of `LoggingTransaction.call_after` and `LoggingTransaction.call_on_exception` when transactions are retried. Signed-off-by: Sean Quah <seanq@element.io>
* Bump `black` and `click` versions (#12320)David Robertson2022-03-291-1/+1
|
* Exclude outliers in `on_backfill_request` (#12314)Richard van der Hoff2022-03-281-3/+9
| | | | | | When we are processing a `/backfill` request from a remote server, exclude any outliers from consideration early on. We can't return outliers anyway (since we don't know the state at the outlier), and filtering them out earlier means that we won't attempt to calulate the state for them.
* Add some type hints to datastore. (#12255)Dirk Klimpel2022-03-288-39/+60
|
* Improve type annotations for `execute_values`. (#12311)reivilibre2022-03-281-10/+7
|
* Add cache for `get_membership_from_event_ids` (#12272)Erik Johnston2022-03-254-8/+55
| | | | | This should speed up push rule calculations for rooms with large numbers of local users when the main push rule cache fails. Co-authored-by: reivilibre <oliverw@matrix.org>
* Refuse to start if DB has an unsafe locale (#12262)Shay2022-03-231-15/+30
|
* Use psycopg2 type stubs (#12269)David Robertson2022-03-232-4/+12
|
* Rename shared_rooms to mutual_rooms (#12036)Jonathan de Jong2022-03-231-3/+3
| | | Co-authored-by: reivilibre <olivier@librepush.net>
* Move get_bundled_aggregations to relations handler. (#12237)Patrick Cloke2022-03-181-146/+5
| | | | | The get_bundled_aggregations code is fairly high-level and uses a lot of store methods, we move it into the handler as that seems like a better fit.
* Only fetch thread participation for events with threads. (#12228)Patrick Cloke2022-03-181-1/+3
| | | | | | | | | We fetch the thread summary in two phases: 1. The summary that is shared by all users (count of messages and latest event). 2. Whether the requesting user has participated in the thread. There's no use in attempting step 2 for events which did not return a summary from step 1.
* Add some type hints to datastore (#12248)Dirk Klimpel2022-03-182-78/+116
| | | | | * inherit `MonthlyActiveUsersStore` from `RegistrationWorkerStore` Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
* Correct `check_username_for_spam` annotations and docs (#12246)David Robertson2022-03-181-4/+19
| | | | | | | * Formally type the UserProfile in user searches * export UserProfile in synapse.module_api * Update docs Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
* Handle cancellation in `DatabasePool.runInteraction()` (#12199)Sean Quah2022-03-161-24/+37
| | | | | | | | | | | | To handle cancellation, we ensure that `after_callback`s and `exception_callback`s are always run, since the transaction will complete on another thread regardless of cancellation. We also wait until everything is done before releasing the `CancelledError`, so that logging contexts won't get used after they have been finished. Signed-off-by: Sean Quah <seanq@element.io>
* Add some missing type hints to cache datastore. (#12216)Patrick Cloke2022-03-161-21/+36
|
* Use the ignored_users table to test event visibility & sync. (#12225)Patrick Cloke2022-03-151-3/+38
| | | | | Instead of fetching the raw account data and re-parsing it. The ignored_users table is a denormalised version of the account data for quick searching.
* Fix broken background updates when using sqlite with `enable_search` off ↵Sean Quah2022-03-141-6/+7
| | | | | (#12215) Signed-off-by: Sean Quah <seanq@element.io>
* Add config settings for background update parameters (#11980)Shay2022-03-111-14/+25
|
* Remove unnecessary pass statements. (#12206)Patrick Cloke2022-03-112-3/+0
|
* Support stable identifiers for MSC3440: Threading (#12151)Patrick Cloke2022-03-103-39/+61
| | | | The unstable identifiers are still supported if the experimental configuration flag is enabled. The unstable identifiers will be removed in a future release.
* Allow retrieving the relations of a redacted event. (#12130)Patrick Cloke2022-03-103-33/+42
| | | | | | | | | This is allowed per MSC2675, although the original implementation did not allow for it and would return an empty chunk / not bundle aggregations. The main thing to improve is that the various caches get cleared properly when an event is redacted, and that edits must not leak if the original event is redacted (as that would presumably leak something similar to the original event content).
* Allow for ignoring some arguments when caching. (#12189)Patrick Cloke2022-03-091-2/+2
| | | | | * `@cached` can now take an `uncached_args` which is an iterable of names to not use in the cache key. * Requires `@cached`, @cachedList` and `@lru_cache` to use keyword arguments for clarity. * Asserts that keyword-only arguments in cached functions are not accepted. (I tested this briefly and I don't believe this works properly.)
* Remove some unused variables/parameters. (#12187)Patrick Cloke2022-03-091-9/+5
|
* Fix a bug in background updates wherein background updates are never run ↵Shay2022-03-071-3/+5
| | | | using the default batch size (#12157)
* Invalidate caches when an event with a relation is redacted. (#12121)Patrick Cloke2022-03-072-5/+35
| | | | | The caches for the target of the relation must be cleared so that the bundled aggregations are re-calculated after the redaction is processed.
* Reduce to-device queries for /sync. (#12163)Erik Johnston2022-03-041-0/+3
|
* Remove backwards compatibility with RelationPaginationToken. (#12138)Patrick Cloke2022-03-041-31/+0
|
* Fix type of `events` in `StateGroupStorage` and `StateHandler` (#12156)Richard van der Hoff2022-03-041-4/+4
| | | We make multiple passes over this, so a regular iterable won't do.
* Back out in-flight state caching changes. (#12126)reivilibre2022-03-021-218/+25
|
* Make get_room_version use cached get_room_version_id. (#11808)lukasdenk2022-03-021-14/+13
|
* Order in-flight state group queries in biggest-first order (#11610)reivilibre2022-03-011-3/+27
| | | Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
* Faster joins: persist to database (#12012)Richard van der Hoff2022-03-015-0/+203
| | | | | | | | | | | | When we get a partial_state response from send_join, store information in the database about it: * store a record about the room as a whole having partial state, and stash the list of member servers too. * flag the join event itself as having partial state * also, for any new events whose prev-events are partial-stated, note that they will *also* be partial-stated. We don't yet make any attempt to interpret this data, so API calls (and a bunch of other things) are just going to get incorrect data.
* Ensure that `get_datastores().main` is typed (#12070)Sean Quah2022-02-251-1/+2
| | | Signed-off-by: Sean Quah <seanq@element.io>
* Minor typing fixes for `synapse/storage/persist_events.py` (#12069)Sean Quah2022-02-252-23/+25
| | | Signed-off-by: Sean Quah <seanq@element.io>
* Add support for MSC3202: sending one-time key counts and fallback key usage ↵reivilibre2022-02-242-2/+143
| | | | | states to Application Services. (#11617) Co-authored-by: Erik Johnston <erik@matrix.org>
* Fix non-strings in the `event_search` table (#12037)Sean Quah2022-02-243-9/+57
| | | | | | | Don't attempt to add non-string `value`s to `event_search` and add a background update to clear out bad rows from `event_search` when using sqlite. Signed-off-by: Sean Quah <seanq@element.io>
* Remove `HomeServer.get_datastore()` (#12031)Richard van der Hoff2022-02-231-1/+1
| | | | | | | The presence of this method was confusing, and mostly present for backwards compatibility. Let's get rid of it. Part of #11733
* Cap the number of in-flight requests for state from a single group (#11608)reivilibre2022-02-221-0/+16
|
* Fix slow performance of `/logout` in some cases where refresh tokens are in ↵reivilibre2022-02-222-2/+44
| | | | use. The slowness existed since the initial implementation of refresh tokens. (#12056)
* remote join processing: get create event from state, not auth_chain (#12039)Richard van der Hoff2022-02-211-2/+2
| | | A follow-up to #12005, in which I apparently missed that there are a bunch of other places that assume the create event is in the auth chain.
* Add type hints to `synapse/storage/databases/main` (#11984)Dirk Klimpel2022-02-213-35/+61
|
* Document why auth providers aren't validated in the admin API. (#12004)Patrick Cloke2022-02-181-0/+21
| | | | Since it is reasonable to give a future or past auth provider, which might not be in the current configuration.
* Track and deduplicate in-flight requests to `_get_state_for_groups`. (#10870)reivilibre2022-02-181-25/+178
| | | Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
* Fix bug in `StateFilter.return_expanded()` and add some tests. (#12016)reivilibre2022-02-181-1/+7
|
* Fix 500 error with Postgres when looking backwards with the MSC3030 ↵Eric Eastwood2022-02-181-1/+1
| | | | `/timestamp_to_event` endpoint (#12024)
* Fix a typo in a comment.Patrick Cloke2022-02-161-1/+1
|