Commit Graph

564 Commits

Author SHA1 Message Date
Šimon Brandner
13e359aec8
Implement MSC3827: Filtering of /publicRooms by room type ()
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
2022-06-29 17:12:45 +00:00
Erik Johnston
92a0c18ef0
Improve performance of getting unread counts in rooms () 2022-06-29 10:32:38 +00:00
Erik Johnston
7469824d58
Fix serialization errors when rotating notifications () 2022-06-28 13:13:44 +01:00
Patrick Cloke
d3d84685ce
Add type hints to event push actions tests. () 2022-06-17 12:38:13 +00:00
Erik Johnston
0d1d3e0708
Speed up get_unread_event_push_actions_by_room ()
Fixes  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.
2022-06-15 15:17:14 +00:00
Erik Johnston
e3163e2e11
Reduce the amount of state we pull from the DB () 2022-06-06 09:24:12 +01:00
Erik Johnston
888a29f412
Wait for lazy join to complete when getting current state () 2022-06-01 16:02:53 +01:00
Patrick Cloke
7bc08f3201
Remove remaining bits of groups code. ()
* 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.
2022-06-01 09:41:25 -04:00
Erik Johnston
1e453053cb
Rename storage classes () 2022-05-31 12:17:50 +00:00
Sumner Evans
bda4600399
LockStore: fix acquiring a lock via LockStore.try_acquire_lock ()
Signed-off-by: Sumner Evans <sumner@beeper.com>
2022-05-30 09:41:13 +01:00
Patrick Cloke
c52abc1cfd
Additional constants for EDU types. ()
Instead of hard-coding strings in many places.
2022-05-27 07:14:36 -04:00
Matt C
a7da00d4f7
Add storage and module API methods to get monthly active users and their appservices () 2022-05-27 10:25:57 +00:00
Erik Johnston
b83bc5fab5
Pull out less state when handling gaps mk2 () 2022-05-26 09:48:12 +00:00
Dirk Klimpel
444588c5fc
Add some type hints to tests files ()
Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
2022-05-23 11:23:26 +00:00
Richard van der Hoff
24b590de32
Remove code which updates application_services_state.last_txn ()
This column is unused as of , so let's stop writing to it.
2022-05-17 11:07:18 +01:00
Erik Johnston
fcf951d5dc
Track in memory events using weakrefs () 2022-05-17 10:34:27 +01:00
Erik Johnston
c72d26c1e1
Refactor EventContext ()
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 
2022-05-10 19:43:13 +00:00
Richard van der Hoff
147f098fb4
Stop writing to event_reference_hashes ()
This table is never read, since . We stop writing to it; in future we can
drop it altogether.
2022-05-10 15:35:08 +01:00
David Robertson
2607b3e181
Update mypy to 0.950 and fix complaints () 2022-05-06 12:35:20 +00:00
Richard van der Hoff
96e0cdbc5a
Add a consistency check on events read from the database ()
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.
2022-05-03 21:27:52 +01:00
Sean Quah
78b99de7c2
Prefer make_awaitable over defer.succeed in tests ()
When configuring the return values of mocks, prefer awaitables from
`make_awaitable` over `defer.succeed`. `Deferred`s are only awaitable
once, so it is inappropriate for a mock to return the same `Deferred`
multiple times.

Also update `run_in_background` to support functions that return
arbitrary awaitables.

Signed-off-by: Sean Quah <seanq@element.io>
2022-04-27 14:58:26 +01:00
Erik Johnston
f59e3f4c90
Mark remote device list updates as already handled () 2022-04-26 17:07:21 +01:00
Sean Quah
8a87b4435a
Handle cancellation in EventsWorkerStore._get_events_from_cache_or_db ()
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>
2022-04-25 19:39:17 +01:00
Richard van der Hoff
f5668f0b4a
Await un-partial-stating after a partial-state join ()
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.
2022-04-21 07:42:03 +01:00
Erik Johnston
0b014eb25e
Only send out device list updates for our own users ()
Broke in 
2022-04-14 13:05:31 +01:00
Erik Johnston
aa28110264
Process device list updates asynchronously () 2022-04-12 16:50:40 +01:00
reivilibre
e630722f11
Optimise _update_client_ips_batch_txn to batch together database operations. ()
Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
2022-04-08 15:29:13 +01:00
Eric Eastwood
793d03e2c5
Generate historic pagination token for /messages when no ?from token provided () 2022-04-06 11:40:28 +01:00
Dirk Klimpel
d666fc02fa
Add type hints to some tests files () 2022-04-05 13:54:41 +01:00
Erik Johnston
5c9e39e619
Track device list updates per room. ()
This is a first step in dealing with .

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.
2022-04-04 15:25:20 +01:00
Richard van der Hoff
f0b03186d9
Add type hints for tests/unittest.py. ()
In particular, add type hints for get_success and friends, which are then helpful in a bunch of places.
2022-04-01 16:04:16 +00:00
Richard van der Hoff
33ebee47e4
Remove redundant get_success calls in test code ()
There are a bunch of places we call get_success on an immediate value, which is unnecessary. Let's rip them out, and remove the redundant functionality in get_success and friends.
2022-04-01 16:10:31 +01:00
reivilibre
c4cf916ed7
Default to private room visibility rather than public when a client does not specify one, according to spec. () 2022-04-01 15:55:09 +01:00
Nick Mills-Barrett
993d90f82b
Use a sequence to generate AS transaction IDs, drop last_txn AS state ()
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.
2022-04-01 13:33:25 +00:00
Richard van der Hoff
b7762b0c9f
Move single-use methods out of TestCase ()
These methods are only used by a single testcase, so they shouldn't be
cluttering up the base `TestCase` class.
2022-04-01 12:48:08 +00:00
Andrew Morgan
d8d0271977
Send device list updates to application services (MSC3202) - part 1 ()
Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
2022-03-30 14:39:27 +01:00
Andrew Morgan
c8cbd66d3b
Start application service stream token tracking from 1 ()
Co-authored-by: Erik Johnston <erik@matrix.org>
2022-03-30 11:10:12 +00:00
Shay
e78d4f61fc
Refuse to start if DB has an unsafe locale () 2022-03-23 10:23:05 -07:00
Dirk Klimpel
9d21ecf7ce
Add type hints to tests files. () 2022-03-21 09:43:16 -04:00
Sean Quah
6121056740
Handle cancellation in DatabasePool.runInteraction() ()
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>
2022-03-16 15:07:41 +00:00
Patrick Cloke
dda9b7fc4d
Use the ignored_users table to test event visibility & sync. ()
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.
2022-03-15 14:06:05 -04:00
Sean Quah
dea577998f
Add tests for database transaction callbacks ()
Signed-off-by: Sean Quah <seanq@element.io>
2022-03-15 15:40:34 +00:00
Shay
ef3619e61d
Add config settings for background update parameters () 2022-03-11 10:46:45 -08:00
Patrick Cloke
ea27528b5d
Support stable identifiers for MSC3440: Threading ()
The unstable identifiers are still supported if the experimental configuration
flag is enabled. The unstable identifiers will be removed in a future release.
2022-03-10 15:36:13 +00:00
Sean Quah
a4c1fdb44a
Remove dead code in tests/storage/test_database.py ()
Signed-off-by: Sean Quah <seanq@element.io>
2022-03-09 18:45:21 +00:00
Shay
26211fec24
Fix a bug in background updates wherein background updates are never run using the default batch size () 2022-03-07 09:44:33 -08:00
reivilibre
c7b2f1ccdc
Back out in-flight state caching changes. () 2022-03-02 10:37:04 +00:00
reivilibre
c893632319
Order in-flight state group queries in biggest-first order ()
Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
2022-03-01 13:41:57 +00:00
Patrick Cloke
02d708568b
Replace assertEquals and friends with non-deprecated versions. () 2022-02-28 07:12:29 -05:00
reivilibre
2cc5ea933d
Add support for MSC3202: sending one-time key counts and fallback key usage states to Application Services. ()
Co-authored-by: Erik Johnston <erik@matrix.org>
2022-02-24 17:55:45 +00:00