summary refs log tree commit diff
path: root/synapse/storage/databases/main/receipts.py (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Update code to refer to "workers". (#15606)Patrick Cloke2023-05-161-5/+2
| | | | A bunch of comments and variables are out of date and use obsolete terms.
* Combine AbstractStreamIdTracker and AbstractStreamIdGenerator. (#15192)Patrick Cloke2023-03-031-3/+3
| | | | | AbstractStreamIdTracker (now) has only a single sub-class: AbstractStreamIdGenerator, combine them to simplify some code and remove any direct references to AbstractStreamIdTracker.
* Bump black from 22.12.0 to 23.1.0 (#15103)dependabot[bot]2023-02-221-1/+0
|
* Return read-only collections from `@cached` methods (#13755)Sean Quah2023-02-101-4/+6
| | | | | | | | | | | | | 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>
* 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.
* Always notify replication when a stream advances (#14877)Erik Johnston2023-01-201-0/+2
| | | This ensures that all other workers are told about stream updates in a timely manner, without having to remember to manually poke replication.
* Update all stream IDs after processing replication rows (#14723)Nick Mills-Barrett2023-01-041-0/+7
| | | | | | | | | | | | | | 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
* Handle half-created indices in receipts index background update (#14650)Sean Quah2022-12-091-39/+12
| | | | | | | | | | | | | 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>
* Reintroduce #14376, with bugfix for monoliths (#14468)David Robertson2022-11-161-9/+9
| | | | | | | | | | | | | | | | | | | | | | * 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>
* 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-161-9/+9
| | | This reverts commit 36097e88c4da51fce6556a58c49bd675f4cf20ab.
* Remove slaved id tracker (#14376)Nick Mills-Barrett2022-11-141-9/+9
| | | | | This matches the multi instance writer ID generator class which can both handle advancing the current token over replication and by calling the database.
* 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.
* 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.
* Clarify that a method returns only unthreaded receipts. (#13937)Patrick Cloke2022-09-291-31/+5
| | | | | By renaming it and updating the docstring. Additionally, refactors a method which is used only by tests.
* Accept & store thread IDs for receipts (implement MSC3771). (#13782)Patrick Cloke2022-09-231-23/+64
| | | | Updates the `/receipts` endpoint and receipt EDU handler to parse a `thread_id` from the body and insert it in the database.
* Update event push action and receipt tables to support threads. (#13753)Patrick Cloke2022-09-141-0/+20
| | | | | | | | | | | | | | | Adds a `thread_id` column to the `event_push_actions`, `event_push_actions_staging`, and `event_push_summary` tables. This will notifications to be segmented by the thread in a future pull request. The `thread_id` column stores the root event ID or the special value `"main"`. The `thread_id` column for `event_push_actions` and `event_push_summary` is backfilled with `"main"` for all existing rows. New entries into `event_push_actions` and `event_push_actions_staging` will get the proper thread ID. `receipts_linearized` and `receipts_graph` also gain a `thread_id` column, which is similar, except `NULL` is a special value meaning the receipt is "unthreaded". See MSC3771 and MSC3773 for where this data will be useful.
* Add receipts event stream ordering (#13703)Nick Mills-Barrett2022-09-131-1/+73
|
* Use an upsert for `receipts_graph`. (#13752)Patrick Cloke2022-09-091-8/+4
| | | | | | Instead of a delete, then insert. This was previously done for `receipts_linearized` in 2dc430d36ef793b38d6d79ec8db4ea60588df2ee (#7607).
* Clarifications for event push action processing. (#13485)Patrick Cloke2022-08-151-1/+1
| | | | | | | | * Clarifies comments. * Fixes an erroneous comment (about return type) added in #13455 (ec24813220f9d54108924dc04aecd24555277b99). * Clarifies the name of a variable. * Simplifies logic of pulling out the latest join for the requesting user.
* Revert "Make all `process_replication_rows` methods async (#13304)" (#13312)Erik Johnston2022-07-181-4/+2
| | | This reverts commit 5d4028f217f178fcd384d5bfddd92225b4e78c51.
* Make all `process_replication_rows` methods async (#13304)Nick Mills-Barrett2022-07-171-2/+4
| | | | | More prep work for asyncronous caching, also makes all process_replication_rows methods consistent (presence handler already is so). Signed off by Nick @ Beeper (@Fizzadar)
* Fix serialization errors when rotating notifications (#13118)Erik Johnston2022-06-281-12/+1
|
* Speed up `get_unread_event_push_actions_by_room` (#13005)Erik Johnston2022-06-151-33/+41
| | | | | | | | | | | Fixes #11887 hopefully. The core change here is that `event_push_summary` now holds a summary of counts up until a much more recent point, meaning that the range of rows we need to count in `event_push_actions` is much smaller. This needs two major changes: 1. When we get a receipt we need to recalculate `event_push_summary` rather than just delete it 2. The logic for deleting `event_push_actions` is now divorced from calculating `event_push_summary`. In future it would be good to calculate `event_push_summary` while we persist a new event (it should just be a case of adding one to the relevant rows in `event_push_summary`), as that will further simplify the get counts logic and remove the need for us to periodically update `event_push_summary` in a background job.
* Use READ COMMITTED isolation level when inserting read receipts (#12957)Nick Mills-Barrett2022-06-091-0/+5
|
* Clean-up some receipts code (#12888)Patrick Cloke2022-05-271-42/+47
| | | | | * Properly marks private methods as private. * Adds missing docstrings. * Rework inline methods.
* Additional constants for EDU types. (#12884)Patrick Cloke2022-05-271-4/+4
| | | Instead of hard-coding strings in many places.
* Avoid attempting to delete push actions for remote users. (#12879)Patrick Cloke2022-05-261-1/+4
| | | | Remote users will never have push actions, so we can avoid a database round-trip/transaction completely.
* Remove unused receipt datastore methods. (#12632)Patrick Cloke2022-05-051-54/+0
| | | The last usage was removed in 5a1dd297c3ce105a7f516d9d9fe87b94b9d356c8 (#8059).
* Implement changes to MSC2285 (hidden read receipts) (#12168)Šimon Brandner2022-05-041-32/+110
| | | | | * Changes hidden read receipts to be a separate receipt type (instead of a field on `m.read`). * Updates the `/receipts` endpoint to accept `m.fully_read`.
* Improve the docstrings for the receipts store. (#12581)Patrick Cloke2022-04-281-5/+51
|
* Prefill more stream change caches. (#12372)Erik Johnston2022-04-051-1/+12
|
* Add some type hints to datastore. (#12255)Dirk Klimpel2022-03-281-12/+25
|
* Type hint the constructors of the data store classes (#11555)Sean Quah2021-12-131-2/+11
|
* Add a constant for receipt types (m.read). (#11531)Patrick Cloke2021-12-081-33/+68
| | | And expand some type hints in the receipts storage module.
* Add type hints for most `HomeServer` parameters (#11095)Sean Quah2021-10-221-2/+5
|
* Add type hints for event streams. (#10856)Patrick Cloke2021-09-211-3/+3
|
* Combine `LruCache.invalidate` and `invalidate_many` (#9973)Richard van der Hoff2021-05-271-4/+2
| | | | | | | | | | * Make `invalidate` and `invalidate_many` do the same thing ... so that we can do either over the invalidation replication stream, and also because they always confused me a bit. * Kill off `invalidate_many` * changelog
* Remove redundant "coding: utf-8" lines (#9786)Jonathan de Jong2021-04-141-1/+0
| | | | | | | Part of #9744 Removes all redundant `# -*- coding: utf-8 -*-` lines from files, as python 3 automatically reads source code as utf-8 now. `Signed-off-by: Jonathan de Jong <jonathan@automatia.nl>`
* Update black, and run auto formatting over the codebase (#9381)Eric Eastwood2021-02-161-3/+4
| | | | | | | - Update black version to the latest - Run black auto formatting over the codebase - Run autoformatting according to [`docs/code_style.md `](https://github.com/matrix-org/synapse/blob/80d6dc9783aa80886a133756028984dbf8920168/docs/code_style.md) - Update `code_style.md` docs around installing black to use the correct version
* Fix some typos.Patrick Cloke2021-02-121-3/+3
|
* Fix receipts or account data not being sent down sync (#9193)Erik Johnston2021-01-211-2/+2
| | | | | Introduced in #9104 This wasn't picked up by the tests as this is all fine the first time you run Synapse (after upgrading), but then when you restart the wrong value is pulled from `stream_positions`.
* Allow moving account data and receipts streams off master (#9104)Erik Johnston2021-01-181-37/+71
|
* Improve appservice handler to send only the most recent read receipts when ↵Will Hunt2020-11-181-1/+6
| | | | | | | | | | | | | | | | | | | no stream_id is stored. (#8744) * Make this line debug (it's noisy) * Don't include from_key for presence if we are at 0 * Limit read receipts for all rooms to 100 * changelog.d/8744.bugfix * Allow from_key to be None * Update 8744.bugfix * The from_key is superflous * Update comment
* Add `DeferredCache.get_immediate` method (#8568)Richard van der Hoff2020-10-191-10/+1
| | | | | | | | | | | * Add `DeferredCache.get_immediate` method A bunch of things that are currently calling `DeferredCache.get` are only really interested in the result if it's completed. We can optimise and simplify this case. * Remove unused 'default' parameter to DeferredCache.get() * another get_immediate instance
* Send some ephemeral events to appservices (#8437)Will Hunt2020-10-151-0/+55
| | | Optionally sends typing, presence, and read receipt information to appservices.
* Use `async with` for ID gens (#8383)Erik Johnston2020-09-231-1/+1
| | | This will allow us to hit the DB after we've finished using the generated stream ID.
* Simplify super() calls to Python 3 syntax. (#8344)Patrick Cloke2020-09-181-2/+2
| | | | | | | This converts calls like super(Foo, self) -> super(). Generated with: sed -i "" -Ee 's/super\([^\(]+\)/super()/g' **/*.py
* Switch metaclass initialization to python 3-compatible syntax (#8326)Jonathan de Jong2020-09-161-5/+3
|
* Convert additional databases to async/await (#8199)Patrick Cloke2020-09-011-5/+9
|
* Convert simple_update* and simple_select* to async (#8173)Patrick Cloke2020-08-271-3/+5
|
* Convert simple_select_one and simple_select_one_onecol to async (#8162)Patrick Cloke2020-08-261-2/+4
|
* Make StreamIdGen `get_next` and `get_next_mult` async (#8161)Erik Johnston2020-08-251-2/+1
| | | | This is mainly so that `StreamIdGenerator` and `MultiWriterIdGenerator` will have the same interface, allowing them to be used interchangeably.
* Convert receipts and events databases to async/await. (#8076)Patrick Cloke2020-08-141-36/+46
|
* Convert misc database code to async (#8087)Patrick Cloke2020-08-141-3/+2
|
* Reduce unnecessary whitespace in JSON. (#7372)David Vo2020-08-071-5/+4
|
* Rename database classes to make some sense (#8033)Erik Johnston2020-08-051-0/+591