summary refs log tree commit diff
path: root/synapse/storage (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Revert "Set thread_id column to non-null for ↵Erik Johnston2023-05-126-224/+234
| | | | | event_push_{actions,actions_staging,summary} (#15437)" (#15580) This reverts commit a7b3e9ce65335e452de216cb42b9e724e8f3ad1d.
* Clean up and clarify "Create or modify Account" Admin API documentation (#15544)Andrew Morgan2023-05-051-0/+16
|
* Factor out an `is_mine_server_name` method (#15542)Sean Quah2023-05-051-1/+1
| | | | | | | | | | | | Add an `is_mine_server_name` method, similar to `is_mine_id`. Ideally we would use this consistently, instead of sometimes comparing against `hs.hostname` and other times reaching into `hs.config.server.server_name`. Also fix a bug in the tests where `hs.hostname` would sometimes differ from `hs.config.server.server_name`. Signed-off-by: Sean Quah <seanq@matrix.org>
* Speed up deleting of old rows in `event_push_actions` (#15531)Erik Johnston2023-05-031-0/+9
| | | Enforce that we use index scans (rather than seq scans), which we also do for state queries. The reason to enforce this is that we can't correctly get PostgreSQL to understand the distribution of `stream_ordering` depends on `highlight`, and so it always defaults (on matrix.org) to sequential scans.
* Speed up rebuilding of the user directory for local users (#15529)Erik Johnston2023-05-032-77/+171
| | | The idea here is to batch up the work.
* Set thread_id column to non-null for ↵Patrick Cloke2023-05-036-234/+224
| | | | | | | | | | | | | event_push_{actions,actions_staging,summary} (#15437) Updates the database schema to require a thread_id (by adding a constraint that the column is non-null) for event_push_actions, event_push_actions_staging, and event_push_actions_summary. For PostgreSQL we add the constraint as NOT VALID, then VALIDATE the constraint a background job to avoid locking the table during an upgrade. For SQLite we simply rebuild the table & copy the data.
* Add config option to forget rooms automatically when users leave them (#15224)Sean Quah2023-05-032-24/+69
| | | | | This is largely based off the stats and user directory updater code. Signed-off-by: Sean Quah <seanq@matrix.org>
* Initial implementation of MSC3981: recursive relations API (#15315)Patrick Cloke2023-05-021-17/+48
| | | | | | | | | | | Adds an optional keyword argument to the /relations API which will recurse a limited number of event relationships. This will cause the API to return not just the events related to the parent event, but also events related to those related to the parent event, etc. This is disabled by default behind an experimental configuration flag and is currently implemented using prefixed parameters.
* Add an admin API endpoint to support per-user feature flags (#15344)Shay2023-04-283-0/+104
|
* Add support for claiming multiple OTKs at once. (#15468)Patrick Cloke2023-04-271-30/+47
| | | | | | | MSC3983 provides a way to request multiple OTKs at once from appservices, this extends this concept to the Client-Server API. Note that this will likely be spit out into a separate MSC, but is currently part of MSC3983.
* Add type hints to schema deltas (#15497)Patrick Cloke2023-04-2728-134/+131
| | | | | | | | | | Cleans-up the schema delta files: * Removes no-op functions. * Adds missing type hints to function parameters. * Fixes any issues with type hints. This also renames one (very old) schema delta to avoid a conflict that mypy complains about.
* Check databases/__init__ and main/cache with mypy. (#15496)Patrick Cloke2023-04-272-9/+11
|
* Add column `full_user_id` to tables `profiles` and `user_filters`. (#15458)Shay2023-04-266-18/+120
|
* Add admin endpoint to query room sizes (#15482)Erik Johnston2023-04-262-0/+115
|
* Add unstable /keys/claim endpoint which always returns fallback keys. (#15462)Patrick Cloke2023-04-251-4/+5
| | | | | | | | | | | | | It can be useful to always return the fallback key when attempting to claim keys. This adds an unstable endpoint for `/keys/claim` which always returns fallback keys in addition to one-time-keys. The fallback key(s) are not marked as "used" unless there are no corresponding OTKs. This is currently defined in MSC3983 (although likely to be split out to a separate MSC). The endpoint shape may change or be requested differently (i.e. a keyword parameter on the current endpoint), but the core logic should be reasonable.
* Re re introduce membership tables event stream ordering (#15356)Nick Mills-Barrett2023-04-256-12/+162
|
* Experimental support for MSC3970: per-device transaction IDs (#15318)Quentin Gliech2023-04-253-18/+136
|
* Modify StoreKeyFetcher to read from server_keys_json. (#15417)Patrick Cloke2023-04-201-12/+87
| | | | | | | | | | | | | | | | | | | | | | | | | | | Before this change: * `PerspectivesKeyFetcher` and `ServerKeyFetcher` write to `server_keys_json`. * `PerspectivesKeyFetcher` also writes to `server_signature_keys`. * `StoreKeyFetcher` reads from `server_signature_keys`. After this change: * `PerspectivesKeyFetcher` and `ServerKeyFetcher` write to `server_keys_json`. * `PerspectivesKeyFetcher` also writes to `server_signature_keys`. * `StoreKeyFetcher` reads from `server_keys_json`. This results in `StoreKeyFetcher` now using the results from `ServerKeyFetcher` in addition to those from `PerspectivesKeyFetcher`, i.e. keys which are directly fetched from a server will now be pulled from the database instead of refetched. An additional minor change is included to avoid creating a `PerspectivesKeyFetcher` (and checking it) if no `trusted_key_servers` are configured. The overall impact of this should be better usage of cached results: * If a server has no trusted key servers configured then it should reduce how often keys are fetched. * if a server's trusted key server does not have a requested server's keys cached then it should reduce how often keys are directly fetched.
* More precise type for LoggingTransaction.execute (#15432)David Robertson2023-04-143-14/+31
| | | | | | * More precise type for LoggingTransaction.execute * Add an annotation for stream_ordering_month_ago This would have spotted the error that was fixed in "Add comma missing from #15382. (#15429)"
* User directory background update speedup (#15435)Erik Johnston2023-04-141-45/+44
| | | | | | | c.f. #15264 The two changes are: 1. Add indexes so that the select / deletes don't do sequential scans 2. Don't repeatedly call `SELECT count(*)` each iteration, as that's slow
* Load `/directory/room/{roomAlias}` endpoint on workers (#15333)Dirk Klimpel2023-04-141-2/+4
| | | | | | | | | * Enable `directory` * move to worker store * newsfile * disable `ClientDirectoryListServer` and `ClientAppserviceDirectoryListServer` for workers
* Improve robustness when handling a perspective key response by deduplicating ↵reivilibre2023-04-131-3/+3
| | | | | | | | | | | | | | | received server keys. (#15423) * Change `store_server_verify_keys` to take a `Mapping[(str, str), FKR]` This is because we already can't handle duplicate keys — leads to cardinality violation * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> --------- Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
* Add comma missing from #15382. (#15429)reivilibre2023-04-131-1/+1
| | | | | | | | | | | * Add missing comma * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> --------- Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
* Implement MSC2175: remove the creator field from create events. (#15394)Patrick Cloke2023-04-061-5/+12
|
* Don't keep old stream_ordering_to_exterm around (#15382)Erik Johnston2023-04-061-10/+42
|
* Merge remote-tracking branch 'origin/release-v1.81' into developPatrick Cloke2023-04-061-1/+1
|\
| * Fix the 'set_device_id_for_pushers_txn' background update. (#15391)Quentin Gliech2023-04-051-1/+1
| | | | | | | | Refer to the correct field from the response when updating the background update progress.
* | Delete server-side backup keys when deactivating an account. (#15181)Shay2023-04-042-3/+128
|/
* Speed up membership queries for users with forgotten rooms (#15385)Erik Johnston2023-04-042-1/+30
|
* Revert pruning of old devices (#15360)Erik Johnston2023-03-311-82/+1
| | | | | | | | | * Revert "Fix registering a device on an account with lots of devices (#15348)" This reverts commit f0d8f66eaaacfa75bed65bc5d0c602fbc5339c85. * Revert "Delete stale non-e2e devices for users, take 3 (#15183)" This reverts commit 78cdb72cd6b0e007c314d9fed9f629dfc5b937a6.
* Revert "Set thread_id column to non-null for ↵Olivier Wilkinson (reivilibre)2023-03-315-153/+243
| | | | | | | | event_push_{actions,actions_staging,summary} (#15350)" This reverts commit 2a234b788e2b5706ee83cf8eb86dfd004bc7c166. See #15359 for context.
* Set thread_id column to non-null for ↵Patrick Cloke2023-03-305-243/+153
| | | | | | | | | | | event_push_{actions,actions_staging,summary} (#15350) Clean-up from adding the thread_id column, which was initially null but backfilled with values. It is desirable to require it to now be non-null. In addition to altering this column to be non-null, we clean up obsolete background jobs, indexes, and just-in-time updating code.
* to_device updates could be dropped when consuming the replication stream ↵Mathieu Velten2023-03-301-10/+4
| | | | | (#15349) Co-authored-by: reivilibre <oliverw@matrix.org>
* Speed up SQLite unit test CI (#15334)Erik Johnston2023-03-301-1/+16
| | | Tests now take 40% of the time.
* Fix spinloop during partial state sync when a prev event is in backoff (#15351)Sean Quah2023-03-301-14/+21
| | | | | | | | Previously, we would spin in a tight loop until `update_state_for_partial_state_event` stopped raising `FederationPullAttemptBackoffError`s. Replace the spinloop with a wait until the backoff period has expired. Signed-off-by: Sean Quah <seanq@matrix.org>
* Fix registering a device on an account with lots of devices (#15348)Erik Johnston2023-03-291-3/+6
| | | Fixes up #15183
* Revert "Reintroduce membership tables event stream ordering (#15128)" (#15347)Erik Johnston2023-03-295-130/+12
| | | This reverts commit e6af49fbea939d9e69ed05e0a0ced5948c722ea4.
* Delete stale non-e2e devices for users, take 3 (#15183)Erik Johnston2023-03-291-1/+79
| | | | | 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.
* Implement MSC3983 to proxy /keys/claim queries to appservices. (#15314)Patrick Cloke2023-03-281-9/+27
| | | | | | Experimental support for MSC3983 is behind a configuration flag. If enabled, for users which are exclusively owned by an application service then the appservice will be queried for one-time keys *if* there are none uploaded to Synapse.
* Bump ruff from 0.0.252 to 0.0.259 (#15328)dependabot[bot]2023-03-285-9/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Bump ruff from 0.0.252 to 0.0.259 Bumps [ruff](https://github.com/charliermarsh/ruff) from 0.0.252 to 0.0.259. - [Release notes](https://github.com/charliermarsh/ruff/releases) - [Changelog](https://github.com/charliermarsh/ruff/blob/main/BREAKING_CHANGES.md) - [Commits](https://github.com/charliermarsh/ruff/compare/v0.0.252...v0.0.259) --- updated-dependencies: - dependency-name: ruff dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Fix new warnings * Mypy * Newsfile --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Erik Johnston <erik@matrix.org>
* As an optimisation, use `TRUNCATE` on Postgres when clearing the user ↵reivilibre2023-03-241-4/+11
| | | | directory tables. (#15316)
* Make cleaning up pushers depend on the device_id instead of the token_id ↵Quentin Gliech2023-03-242-9/+50
| | | | | | | | | | | | | | (#15280) This makes it so that we rely on the `device_id` to delete pushers on logout, instead of relying on the `access_token_id`. This ensures we're not removing pushers on token refresh, and prepares for a world without access token IDs (also known as the OIDC). This actually runs the `set_device_id_for_pushers` background update, which was forgotten in #13831. Note that for backwards compatibility it still deletes pushers based on the `access_token` until the background update finishes.
* Reintroduce membership tables event stream ordering (#15128)Nick Mills-Barrett2023-03-245-12/+130
| | | | | | | | | | | | | | | | | | * Add `event_stream_ordering` column to membership state tables Specifically this adds the column to `current_state_events`, `local_current_membership` and `room_memberships`. Each of these tables is regularly joined with the `events` table to get the stream ordering and denormalising this into each table will yield significant query performance improvements once used. * Make denormalised `event_stream_ordering` columns foreign keys * Add comment in schema file explaining new denormalised columns * Add triggers to enforce consistency of `event_stream_ordering` columns * Re-order purge room tables to account for foreign keys * Bump schema version to 75 Co-authored-by: David Robertson <david.m.robertson1@gmail.com> Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Use immutabledict instead of frozendict (#15113)David Robertson2023-03-221-2/+2
| | | | | | | | | | Additionally: * Consistently use `freeze()` in test --------- Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com> Co-authored-by: 6543 <6543@obermui.de>
* Apply & bundle edits for non-message events. (#15295)Patrick Cloke2023-03-211-7/+4
|
* Make `POST /_matrix/client/v3/rooms/{roomId}/report/{eventId}` endpoint ↵Andrew Morgan2023-03-211-1/+0
| | | | return 404 if event exists, but the user lacks access (#15300)
* Refresh remote profiles that have been marked as stale, in order to fill the ↵reivilibre2023-03-161-0/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | user directory. [rei:userdirpriv] (#14756) * Scaffolding for background process to refresh profiles * Add scaffolding for background process to refresh profiles for a given server * Implement the code to select servers to refresh from * Ensure we don't build up multiple looping calls * Make `get_profile` able to respect backoffs * Add logic for refreshing users * When backing off, schedule a refresh when the backoff is over * Wake up the background processes when we receive an interesting state event * Add tests * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> * Add comment about 1<<62 --------- Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
* Preparatory work to fix the user directory assuming that any remote ↵reivilibre2023-03-162-0/+79
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | membership state events represent a profile change. [rei:userdirpriv] (#14755) * Remove special-case method for new memberships only, use more generic method * Only collect profiles from state events in public rooms * Add a table to track stale remote user profiles * Add store methods to set and delete rows in this new table * Mark remote profiles as stale when a member state event comes in to a private room * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> * Simplify by removing Optionality of `event_id` * Replace names and avatars with None if they're set to dodgy things I think this makes more sense anyway. * Move schema delta to 74 (I missed the boat?) * Turns out these can be None after all --------- Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org>
* Add schema comments about the `destinations` and `destination_rooms` tables. ↵reivilibre2023-03-151-0/+52
| | | | (#15247)
* Remove unused store method `_set_destination_retry_timings_emulated`. (#15266)reivilibre2023-03-141-54/+2
|
* Add missing type hints to `synapse.storage.database`. (#15230)Patrick Cloke2023-03-091-5/+16
|
* Include the room ID in more purge room log lines. (#15222)Patrick Cloke2023-03-083-14/+21
|
* Split up txn for fetching device keys (#15215)Erik Johnston2023-03-072-9/+25
| | | | We look up keys in batches, but we should do that outside of the transaction to avoid starving the database pool.
* Combine AbstractStreamIdTracker and AbstractStreamIdGenerator. (#15192)Patrick Cloke2023-03-036-27/+14
| | | | | AbstractStreamIdTracker (now) has only a single sub-class: AbstractStreamIdGenerator, combine them to simplify some code and remove any direct references to AbstractStreamIdTracker.
* Experimental MSC3890 Implementation: Fix deleting account data when using an ↵Andrew Morgan2023-03-031-19/+15
| | | | account data writer worker (#14869)
* Add a `get_next_txn` method to `StreamIdGenerator` to match ↵Andrew Morgan2023-03-023-11/+47
| | | | `MultiWriterIdGenerator` (#15191
* Move event_reports to `RoomWorkerStore` (#15165)Dirk Klimpel2023-03-021-177/+177
|
* Remove support for aggregating reactions (#15172)Richard van der Hoff2023-02-284-147/+0
| | | | | | | | | | It turns out that no clients rely on server-side aggregation of `m.annotation` relationships: it's just not very useful as currently implemented. It's also non-trivial to calculate. I want to remove it from MSC2677, so to keep the implementation in line, let's remove it here.
* Fix a long-standing bug where an initial sync would not respond to changes ↵reivilibre2023-02-281-0/+31
| | | | to the list of ignored users if there was an initial sync cached. (#15163)
* Allow use of the `/filter` Client-Server APIs on workers. (#15134)reivilibre2023-02-282-6/+23
|
* Admin API endpoint to delete a reported event (#15116)Dirk Klimpel2023-02-281-1/+35
| | | | | | | | | | | | | | | | | | | | | * Admin api to delete event report * lint + tests * newsfile * Apply suggestions from code review Co-authored-by: David Robertson <david.m.robertson1@gmail.com> * revert changes - move to WorkerStore * update unit test * Note that timestamp is in millseconds --------- Co-authored-by: David Robertson <david.m.robertson1@gmail.com>
* Add module API callbacks for adding and deleting local 3PID associations (#15044Andrew Morgan2023-02-271-13/+0
|
* Batch up storing state groups when creating new room (#14918)Shay2023-02-241-0/+119
|
* Improve handling of non-ASCII characters in user directory search (#15143)Sean Quah2023-02-241-2/+50
| | | | | | | | | | | | | | | * Fix a long-standing bug where non-ASCII characters in search terms, including accented letters, would not match characters in a different case. * Fix a long-standing bug where search terms using combining accents would not match display names using precomposed accents and vice versa. To fully take effect, the user directory must be rebuilt after this change. Fixes #14630. Signed-off-by: Sean Quah <seanq@matrix.org>
* Bump black from 22.12.0 to 23.1.0 (#15103)dependabot[bot]2023-02-2221-35/+18
|
* Fix a bug introduced in Synapse v1.74.0 where searching with colons when ↵reivilibre2023-02-201-4/+20
| | | | | | using ICU for search term tokenisation would fail with an error. (#15079) Co-authored-by: David Robertson <davidr@element.io>
* Use mypy 1.0 (#15052)David Robertson2023-02-162-14/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Update mypy and mypy-zope * Remove unused ignores These used to suppress ``` synapse/storage/engines/__init__.py:28: error: "__new__" must return a class instance (got "NoReturn") [misc] ``` and ``` synapse/http/matrixfederationclient.py:1270: error: "BaseException" has no attribute "reasons" [attr-defined] ``` (note that we check `hasattr(e, "reasons")` above) * Avoid empty body warnings, sometimes by marking methods as abstract E.g. ``` tests/handlers/test_register.py:58: error: Missing return statement [empty-body] tests/handlers/test_register.py:108: error: Missing return statement [empty-body] ``` * Suppress false positive about `JaegerConfig` Complaint was ``` synapse/logging/opentracing.py:450: error: Function "Type[Config]" could always be true in boolean context [truthy-function] ``` * Fix not calling `is_state()` Oops! ``` tests/rest/client/test_third_party_rules.py:428: error: Function "Callable[[], bool]" could always be true in boolean context [truthy-function] ``` * Suppress false positives from ParamSpecs ```` synapse/logging/opentracing.py:971: error: Argument 2 to "_custom_sync_async_decorator" has incompatible type "Callable[[Arg(Callable[P, R], 'func'), **P], _GeneratorContextManager[None]]"; expected "Callable[[Callable[P, R], **P], _GeneratorContextManager[None]]" [arg-type] synapse/logging/opentracing.py:1017: error: Argument 2 to "_custom_sync_async_decorator" has incompatible type "Callable[[Arg(Callable[P, R], 'func'), **P], _GeneratorContextManager[None]]"; expected "Callable[[Callable[P, R], **P], _GeneratorContextManager[None]]" [arg-type] ```` * Drive-by improvement to `wrapping_logic` annotation * Workaround false "unreachable" positives See https://github.com/Shoobx/mypy-zope/issues/91 ``` tests/http/test_proxyagent.py:626: error: Statement is unreachable [unreachable] tests/http/test_proxyagent.py:762: error: Statement is unreachable [unreachable] tests/http/test_proxyagent.py:826: error: Statement is unreachable [unreachable] tests/http/test_proxyagent.py:838: error: Statement is unreachable [unreachable] tests/http/test_proxyagent.py:845: error: Statement is unreachable [unreachable] tests/http/federation/test_matrix_federation_agent.py:151: error: Statement is unreachable [unreachable] tests/http/federation/test_matrix_federation_agent.py:452: error: Statement is unreachable [unreachable] tests/logging/test_remote_handler.py:60: error: Statement is unreachable [unreachable] tests/logging/test_remote_handler.py:93: error: Statement is unreachable [unreachable] tests/logging/test_remote_handler.py:127: error: Statement is unreachable [unreachable] tests/logging/test_remote_handler.py:152: error: Statement is unreachable [unreachable] ``` * Changelog * Tweak DBAPI2 Protocol to be accepted by mypy 1.0 Some extra context in: - https://github.com/matrix-org/python-canonicaljson/pull/57 - https://github.com/python/mypy/issues/6002 - https://mypy.readthedocs.io/en/latest/common_issues.html#covariant-subtyping-of-mutable-protocol-members-is-rejected * Pull in updated canonicaljson lib so the protocol check just works * Improve comments in opentracing I tried to workaround the ignores but found it too much trouble. I think the corresponding issue is https://github.com/python/mypy/issues/12909. The mypy repo has a PR claiming to fix this (https://github.com/python/mypy/pull/14677) which might mean this gets resolved soon? * Better annotation for INTERACTIVE_AUTH_CHECKERS * Drive-by AUTH_TYPE annotation, to remove an ignore
* Fix order of partial state tables when purging (#15068)David Robertson2023-02-141-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Fix order of partial state tables when purging `partial_state_rooms` has an FK on `events` pointing to the join event we get from `/send_join`, so we must delete from that table before deleting from `events`. **NB:** It would be nice to cancel any resync processes for the room being purged. We do not do this at present. To do so reliably we'd need an internal HTTP "replication" endpoint, because the worker doing the resync process may be different to that handling the purge request. The first time the resync process tries to write data after the deletion it will fail because we have deleted necessary data e.g. auth events. AFAICS it will not retry the resync, so the only downside to not cancelling the resync is a scary-looking traceback. (This is presumably extremely race-sensitive.) * Changelog * admist(?) -> between * Warn about a race * Fix typo, thanks Sean Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> --------- Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
* Fix clashing DB txn name (#15070)Erik Johnston2023-02-141-1/+1
| | | | | * Fix clashing DB txn name * Newsfile
* Skip calculating unread push actions in `/sync` when `enable_push` is false. ↵Erik Johnston2023-02-141-0/+7
| | | | (#14980)
* Change collection[str] to StrCollection in event_auth code (#14929)Harishankar Kumar2023-02-142-7/+6
| | | Signed-off-by: Harishankar Kumar <hari01584@gmail.com>
* Faster joins: don't stall when a user joins during a fast join (#14606)Mathieu Velten2023-02-101-20/+1
| | | | | | | | | | | | | | | | Fixes #12801. Complement tests are at https://github.com/matrix-org/complement/pull/567. Avoid blocking on full state when handling a subsequent join into a partial state room. Also always perform a remote join into partial state rooms, since we do not know whether the joining user has been banned and want to avoid leaking history to banned users. Signed-off-by: Mathieu Velten <mathieuv@matrix.org> Co-authored-by: Sean Quah <seanq@matrix.org> Co-authored-by: David Robertson <davidr@element.io>
* Return read-only collections from `@cached` methods (#13755)Sean Quah2023-02-1015-55/+74
| | | | | | | | | | | | | It's important that collections returned from `@cached` methods are not modified, otherwise future retrievals from the cache will return the modified collection. This applies to the return values from `@cached` methods and the values inside the dictionaries returned by `@cachedList` methods. It's not necessary for the dictionaries returned by `@cachedList` methods themselves to be read-only. Signed-off-by: Sean Quah <seanq@matrix.org> Co-authored-by: David Robertson <davidr@element.io>
* Avoid fetching unused account data in sync. (#14973)Patrick Cloke2023-02-101-36/+91
| | | | | | | The per-room account data is no longer unconditionally fetched, even if all rooms will be filtered out. Global account data will not be fetched if it will all be filtered out.
* Merge branch 'release-v1.77' into developDavid Robertson2023-02-101-2/+7
|\
| * Bump schema version (#15036)David Robertson2023-02-091-2/+7
| | | | | | | | | | | | | | | | * Bump schema version This should have been included in f10caa73eee0caa91cf373966104d1ededae2aee (and #14979). * Changelog
* | Refactor get_user_devices_from_cache to avoid mutating cached values. (#15040)Patrick Cloke2023-02-101-14/+17
| | | | | | | | | | | | | | | | The previous version of the code could mutate a cached value, but only if the input requested all devices of a user *and* a specific device. To avoid this nonsensical situation we no longer fetch a specific device ID if all of a user's devices are returned.
* | Fix exception on start up about device lists (#15041)Erik Johnston2023-02-101-0/+1
| | | | | | Fixes #15010.
* | Do not always start a db txn on Postgres (#14840)Andrew Morgan2023-02-091-4/+9
| |
* | Add final type hint to synapse.server. (#15035)Patrick Cloke2023-02-093-1/+4
|/
* Disambiguate `get_ex_outlier_stream_rows` queryDavid Robertson2023-02-071-4/+4
| | | | A backwards-compatible piece of #14979 that's safe to land now.
* Revert "Add `event_stream_ordering` column to membership state tables (#14979)"David Robertson2023-02-074-145/+11
| | | | This reverts commit 5fdc12f482c68e2cdbb78d7db5de2cfe621720d4.
* Add `event_stream_ordering` column to membership state tables (#14979)Nick Mills-Barrett2023-02-074-11/+145
| | | | | | | | | | | | This adds an `event_stream_ordering` column to `current_state_events`, `local_current_membership` and `room_memberships`. Each of these tables is regularly joined with the `events` table to get the stream ordering and denormalising this into each table will yield significant query performance improvements once used. Includes a background job to populate these values from the `events` table. Same idea as https://github.com/matrix-org/synapse/pull/13703. Signed off by Nick @ Beeper (@fizzadar).
* Type hints for tests.appservice (#14990)David Robertson2023-02-061-2/+12
| | | | | | | | | | | | | | | | | | | | * Accept a Sequence of events in synapse.appservice This avoids some casts/ignores in the tests I'm about to fixup. It seems that `List[Mock]` is not a subtype of `List[EventBase]`, but `Sequence[Mock]` is a subtype of `Sequence[EventBase]`. So presumably `Mock` is considered a subtype of anything, much like `Any`. * make tests.appservice.test_scheduler pass mypy * Extra hints in tests.appservice.test_scheduler * Extra hints in tests.appservice.test_api * Extra hints in tests.appservice.test_appservice * Disallow untyped defs * Changelog
* Implement MSC3958: suppress notifications from edits (#14960)Patrick Cloke2023-02-031-0/+1
| | | | | | | | Co-authored-by: Brad Murray <brad@beeper.com> Co-authored-by: Nick Barrett <nick@beeper.com> Copy the suppress_edits push rule from Beeper to implement MSC3958. https://github.com/beeper/synapse/blame/9415a1284b1bfb558bd66f28c24ca1611e6c6fa2/rust/src/push/base_rules.rs#L98-L114
* Faster joins: Refactor handling of servers in room (#14954)Sean Quah2023-02-032-18/+35
| | | | | | | | | | | | | | Ensure that the list of servers in a partial state room always contains the server we joined off. Also refactor `get_partial_state_servers_at_join` to return `None` when the given room is no longer partial stated, to explicitly indicate when the room has partial state. Otherwise it's not clear whether an empty list means that the room has full state, or the room is partial stated, but the server we joined off told us that there are no servers in the room. Signed-off-by: Sean Quah <seanq@matrix.org>
* Fetch fewer events when getting hosts in room (#14962)David Robertson2023-02-021-2/+44
|
* Add helper to parse an enum from query args & use it. (#14956)Patrick Cloke2023-02-016-22/+27
| | | | | | | | The `parse_enum` helper pulls an enum value from the query string (by delegating down to the parse_string helper with values generated from the enum). This is used to pull out "f" and "b" in most places and then we thread the resulting Direction enum throughout more code.
* Attempt to delete more duplicate rows in receipts_linearized table. (#14915)Patrick Cloke2023-02-011-8/+26
| | | | | | | | | The previous assumption was that the stream_id column was unique (for a room ID, receipt type, user ID tuple), but this turned out to be incorrect. Now find the max stream ID, then map this back to a database-specific row identifier and delete other rows which match the (room ID, receipt type, user ID) tuple, but *not* the row ID.
* Make sqlite database migrations transactional again, part two (#14926)Sean Quah2023-01-313-5/+12
| | | | | | | | | | | | | | | | #14910 fixed the regression introduced by #13873 where sqlite database migrations would no longer run inside a transaction. However, it committed the transaction before Synapse updated its bookkeeping of which migrations have been run, which means that migrations may be run again after they have completed successfully. Leave the transaction open at the end of `executescript`, to restore the old, correct behaviour. Also make the PostgreSQL behaviour consistent with SQLite. Fixes #14909. Signed-off-by: Sean Quah <seanq@matrix.org>
* Prefer `type(x) is int` to `isinstance(x, int)` (#14945)David Robertson2023-01-311-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Perfer `type(x) is int` to `isinstance(x, int)` This covered all additional instances I could see where `x` was user-controlled. The remaining cases are ``` $ rg -s 'isinstance.*[^_]int' tests/replication/_base.py 576: if isinstance(obj, int): synapse/util/caches/stream_change_cache.py 136: assert isinstance(stream_pos, int) 214: assert isinstance(stream_pos, int) 246: assert isinstance(stream_pos, int) 267: assert isinstance(stream_pos, int) synapse/replication/tcp/external_cache.py 133: if isinstance(result, int): synapse/metrics/__init__.py 100: if isinstance(calls, (int, float)): synapse/handlers/appservice.py 262: assert isinstance(new_token, int) synapse/config/_util.py 62: if isinstance(p, int): ``` which cover metrics, logic related to `jsonschema`, and replication and data streams. AFAICS these are all internal to Synapse * Changelog
* Implement MSC3952: Intentional mentions (#14823)Patrick Cloke2023-01-271-0/+1
| | | | | | | | MSC3952 defines push rules which searches for mentions in a list of Matrix IDs in the event body, instead of searching the entire event body for display name / local part. This is implemented behind an experimental configuration flag and does not yet implement the backwards compatibility pieces of the MSC.
* Merge branch 'release-v1.76' into developDavid Robertson2023-01-273-4/+26
|\
| * Batch look-ups to see if rooms are partial stated. (#14917)Patrick Cloke2023-01-262-4/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Batch look-ups to see if rooms are partial stated. * Fix issues found in linting. * Fix typo. * Apply suggestions from code review Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> * Clarify comments. Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> * Also improve the cache size while we're at it * is_partial_state_rooms -> is_partial_state_room_batched * Run `black` * Improve annotation for `simple_select_many_batch` * Fix is_partial_state_room_batched impl * Okay, _actually_ fix impl * Update description. * Update synapse/storage/databases/main/room.py Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com> * Run black. Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> Co-authored-by: David Robertson <davidr@element.io>
| * Fix initialization of `_device_list_id_gen` (#14914)Sean Quah2023-01-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On startup, the `_device_list_id_gen` stream id generator is initialized using the maximum stream id seen in a list of tables. When we started populating the `device_list_remote_pending` table in #13913, we forgot to add it to the aforementioned list of tables, so the stream id generator can hand out old stream ids after a restart. The end result is that Synapse can fail to handle device list update EDUs after a restart when a partial state join is in progress. Add the `device_list_remote_pending` table to the list of tables to consider when initializing the `_device_list_id_gen` stream id generator. Signed-off-by: Sean Quah <seanq@matrix.org>
* | Use an enum for direction. (#14927)Patrick Cloke2023-01-272-32/+35
| | | | | | | | For better type safety we use an enum instead of strings to configure direction (backwards or forwards).
* | Fix paginating /relations with a live token (#14866)Patrick Cloke2023-01-262-70/+122
|/ | | | | The `/relations` endpoint was not properly handle "live tokens" (i.e sync tokens), to do this properly we abstract the code that `/messages` has and re-use it.
* Make sqlite database migrations transactional again (#14910)Sean Quah2023-01-252-2/+6
| | | | | | | | | | #13873 introduced a regression which causes sqlite database migrations to no longer run inside a transaction. Wrap them in a transaction again, to avoid database corruption when migrations are interrupted. Fixes #14909. Signed-off-by: Sean Quah <seanq@matrix.org>
* Request partial joins by default (#14905)David Robertson2023-01-241-6/+34
| | | | | | | | | | | | | | | | | | | | | | | | | * Request partial joins by default This is a little sloppy, but we are trying to gain confidence in faster joins in the upcoming RC. Admins can still opt out by adding the following to their Synapse config: ```yaml experimental: faster_joins: false ``` We may revert this change before the release proper, depending on how testing in the wild goes. * Changelog * Try to fix the backfill test failures * Upgrade notes * Postgres compat?
* Faster joins: omit partial rooms from eager syncs until the resync completes ↵David Robertson2023-01-233-11/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (#14870) * Allow `AbstractSet` in `StrCollection` Or else frozensets are excluded. This will be useful in an upcoming commit where I plan to change a function that accepts `List[str]` to accept `StrCollection` instead. * `rooms_to_exclude` -> `rooms_to_exclude_globally` I am about to make use of this exclusion mechanism to exclude rooms for a specific user and a specific sync. This rename helps to clarify the distinction between the global config and the rooms to exclude for a specific sync. * Better function names for internal sync methods * Track a list of excluded rooms on SyncResultBuilder I plan to feed a list of partially stated rooms for this sync to ignore * Exclude partial state rooms during eager sync using the mechanism established in the previous commit * Track un-partial-state stream in sync tokens So that we can work out which rooms have become fully-stated during a given sync period. * Fix mutation of `@cached` return value This was fouling up a complement test added alongside this PR. Excluding a room would mean the set of forgotten rooms in the cache would be extended. This means that room could be erroneously considered forgotten in the future. Introduced in #12310, Synapse 1.57.0. I don't think this had any user-visible side effects (until now). * SyncResultBuilder: track rooms to force as newly joined Similar plan as before. We've omitted rooms from certain sync responses; now we establish the mechanism to reintroduce them into future syncs. * Read new field, to present rooms as newly joined * Force un-partial-stated rooms to be newly-joined for eager incremental syncs only, provided they're still fully stated * Notify user stream listeners to wake up long polling syncs * Changelog * Typo fix Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> * Unnecessary list cast Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> * Rephrase comment Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> * Another comment Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com> * Fixup merge(?) * Poke notifier when receiving un-partial-stated msg over replication * Fixup merge whoops Thanks MV :) Co-authored-by: Mathieu Velen <mathieuv@matrix.org> Co-authored-by: Mathieu Velten <mathieuv@matrix.org> Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
* Skip processing stats for broken rooms. (#14873)Patrick Cloke2023-01-232-2/+17
| | | | | | | * Skip processing stats for broken rooms. * Newsfragment * Use a custom exception.
* Faster joins: Update room stats and the user directory on workers when ↵Sean Quah2023-01-231-2/+0
| | | | | | | | | | | | | | | | | | | | | | | finishing join (#14874) * Faster joins: Update room stats and user directory on workers when done When finishing a partial state join to a room, we update the current state of the room without persisting additional events. Workers receive notice of the current state update over replication, but neglect to wake the room stats and user directory updaters, which then get incidentally triggered the next time an event is persisted or an unrelated event persister sends out a stream position update. We wake the room stats and user directory updaters at the appropriate time in this commit. Part of #12814 and #12815. Signed-off-by: Sean Quah <seanq@matrix.org> * fixup comment Signed-off-by: Sean Quah <seanq@matrix.org>
* Enable Faster Remote Room Joins against worker-mode Synapse. (#14752)reivilibre2023-01-223-12/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Enable Complement tests for Faster Remote Room Joins on worker-mode * (dangerous) Add an override to allow Complement to use FRRJ under workers * Newsfile Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> * Fix race where we didn't send out replication notification * MORE HACKS * Fix get_un_partial_stated_rooms_token to take instance_name * Fix bad merge * Remove warning * Correctly advance un_partial_stated_room_stream * Fix merge * Add another notify_replication * Fixups * Create a separate ReplicationNotifier * Fix test * Fix portdb * Create a separate ReplicationNotifier * Fix test * Fix portdb * Fix presence test * Newsfile * Apply suggestions from code review * Update changelog.d/14752.misc Co-authored-by: Erik Johnston <erik@matrix.org> * lint Signed-off-by: Olivier Wilkinson (reivilibre) <oliverw@matrix.org> Co-authored-by: Erik Johnston <erik@matrix.org>
* Always notify replication when a stream advances (#14877)Erik Johnston2023-01-2012-7/+54
| | | This ensures that all other workers are told about stream updates in a timely manner, without having to remember to manually poke replication.
* Implement MSC3930: polls push rules (#14787)Andrew Morgan2023-01-191-1/+2
|
* Wait for streams to catch up when processing HTTP replication. (#14820)Erik Johnston2023-01-181-15/+19
| | | | This should hopefully mitigate a class of races where data gets out of sync due a HTTP replication request racing with the replication streams.
* Merge device list replication streams (#14833)Erik Johnston2023-01-171-6/+7
|
* Merge account data streams (#14826)Erik Johnston2023-01-132-45/+15
|
* Drop unused table `presence` (#14825)Dirk Klimpel2023-01-131-0/+17
|
* Merge remote-tracking branch 'origin/release-v1.75' into developRichard van der Hoff2023-01-121-6/+59
|\
| * Fix race calling `/members?at=` (#14817)Erik Johnston2023-01-121-6/+59
| | | | | | Fixes #14814
* | Add index to improve performance of the `/timestamp_to_event` endpoint used ↵reivilibre2023-01-112-0/+29
|/ | | | for jumping to a specific date in the timeline of a room. (#14799)
* Batch up replication requests to request the resyncing of remote users's ↵reivilibre2023-01-101-8/+22
| | | | devices. (#14716)
* Update all stream IDs after processing replication rows (#14723)Nick Mills-Barrett2023-01-0411-20/+91
| | | | | | | | | | | | | | This creates a new store method, `process_replication_position` that is called after `process_replication_rows`. By moving stream ID advances here this guarantees any relevant cache invalidations will have been applied before the stream is advanced. This avoids race conditions where Python switches between threads mid way through processing the `process_replication_rows` method where stream IDs may be advanced before caches are invalidated due to class resolution ordering. See this comment/issue for further discussion: https://github.com/matrix-org/synapse/issues/14158#issuecomment-1344048703
* Add experimental support for MSC3391: deleting account data (#14714)Andrew Morgan2023-01-012-14/+238
|
* Faster remote room joins: invalidate caches and unblock requests when ↵reivilibre2022-12-192-13/+32
| | | | receiving un-partial-stated event notifications over replication. [rei:frrj/streams/unpsr] (#14546)
* Faster remote room joins: stream the un-partial-stating of events over ↵reivilibre2022-12-144-9/+167
| | | | replication. [rei:frrj/streams/unpsr] (#14545)
* Delete event_push_summary_unique_index again. (#14669)Patrick Cloke2022-12-142-9/+33
| | | | | | | | | | | | | | | | | | if a Synapse deployment upgraded (from < 1.62.0 to >= 1.70.0) then it is possible for schema deltas to run before background updates causing drift in the database schema due to: 1. A delta registered a background update to create an index. 2. A delta dropped the above index if it exists (but it yet exist won't since the background job hasn't run). 3. The code assumed the index was dropped. To fix this we: 1. Cancel the background update which could create the index. 2. Drop the index again. 3. Drop a related index which is dropped by the background update.
* Allow selecting "prejoin" events by state keys (#14642)David Robertson2022-12-131-14/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Declare new config * Parse new config * Read new config * Don't use trial/our TestCase where it's not needed Before: ``` $ time trial tests/events/test_utils.py > /dev/null real 0m2.277s user 0m2.186s sys 0m0.083s ``` After: ``` $ time trial tests/events/test_utils.py > /dev/null real 0m0.566s user 0m0.508s sys 0m0.056s ``` * Helper to upsert to event fields without exceeding size limits. * Use helper when adding invite/knock state Now that we allow admins to include events in prejoin room state with arbitrary state keys, be a good Matrix citizen and ensure they don't accidentally create an oversized event. * Changelog * Move StateFilter tests should have done this in #14668 * Add extra methods to StateFilter * Use StateFilter * Ensure test file enforces typed defs; alphabetise * Workaround surprising get_current_state_ids * Whoops, fix mypy
* Enable `--warn-redundant-casts` option in mypy (#14671)David Robertson2022-12-122-2/+3
| | | | | | | | | | | | | | | | | | | * Enable `--warn-redundant-casts` option in mypy Doesn't do much but helps me sleep better at night. * Changelog * Fix name of the ignore * Fix one more missed cast Not sure why I didn't see this one locally, maybe I needed a poetry update * Remove old comment Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com> Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
* Move `StateFilter` to `synapse.types` (#14668)David Robertson2022-12-126-572/+5
| | | | | * Move `StateFilter` to `synapse.types` * Changelog
* Revert the deletion of stale devices due to performance issues. (#14662)reivilibre2022-12-121-83/+1
|
* Add optional ICU support for user search (#14464)Brendan Abolivier2022-12-121-4/+63
| | | | | | | Fixes #13655 This change uses ICU (International Components for Unicode) to improve boundary detection in user search. This change also adds a new dependency on libicu-dev and pkg-config for the Debian packages, which are available in all supported distros.
* Handle half-created indices in receipts index background update (#14650)Sean Quah2022-12-092-48/+58
| | | | | | | | | | | | | When Synapse is terminated while running the background update to create the `receipts_graph` or `receipts_linearized` indexes, the indexes may be successfully created (or marked as invalid on postgres) while the background update remains unfinished. When Synapse next starts up, the background update will fail because the index already exists, or exists but is invalid on postgres. Use the existing code to create indices in background updates, since it handles these edge cases. Signed-off-by: Sean Quah <seanq@matrix.org>
* Require types in tests.storage. (#14646)Patrick Cloke2022-12-091-1/+1
| | | | Adds missing type hints to `tests.storage` package and does not allow untyped definitions.
* Limit the number of devices we delete at once (#14649)Erik Johnston2022-12-091-3/+8
|
* Delete stale non-e2e devices for users, take 2 (#14595)Erik Johnston2022-12-091-1/+78
| | | | | 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.
* Rebuild the user directory and stats tables. (#14643)Patrick Cloke2022-12-081-0/+29
| | | | | | | | | | | Due to the various fixes to the StreamChangeCache it is not safe to trust the information in the user directory or room/user stats tables. Rebuild them as background jobs. In particular see da777207528513c858395758bf4c023da2c2c1a3 (#14639), and 6a8310f3dfe77acf59df2fe3e88a71b85b9b3ecc (#14435). Maybe also be related to fac8a38525387e344e3595a092578e0ffedd49ae (#14592).
* Fix a long-standing bug where the user directory would return 1 more row ↵reivilibre2022-12-071-1/+1
| | | | than requested. (#14631)
* Improve logging and opentracing for to-device message handling (#14598)Richard van der Hoff2022-12-061-17/+75
| | | | | | | A batch of changes intended to make it easier to trace to-device messages through the system. The intention here is that a client can set a property org.matrix.msgid in any to-device message it sends. That ID is then included in any tracing or logging related to the message. (Suggestions as to where this field should be documented welcome. I'm not enthusiastic about speccing it - it's very much an optional extra to help with debugging.) I've also generally improved the data we send to opentracing for these messages.
* Better return type for `get_all_entities_changed` (#14604)Erik Johnston2022-12-051-40/+71
| | | | Help callers from using the return value incorrectly by ensuring that callers explicitly check if there was a cache hit or not.
* Faster remote room joins: stream the un-partial-stating of rooms over ↵reivilibre2022-12-053-66/+223
| | | | replication. [rei:frrj/streams/unpsr] (#14473)
* Properly handle unknown results for the stream change cache. (#14592)Patrick Cloke2022-12-021-14/+19
| | | | | | StreamChangeCache.get_all_changed_entities can return None to signify it does not have information at the given stream position. Two callers (related to device lists and presence) were treating this response the same as an empty list (i.e. there being no updates).
* Merge branch 'release-v1.73' into developDavid Robertson2022-12-011-66/+1
|\
| * Revert "POC delete stale non-e2e devices for users (#14038)" (#14582)David Robertson2022-11-291-67/+1
| |
| * 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)
* | Aggregate unread notif count query for badge count calculation (#14255)Nick Mills-Barrett2022-11-301-0/+149
|/ | | | | | Fetch the unread notification counts used by the badge counts in push notifications for all rooms at once (instead of fetching them per room).
* 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)