summary refs log tree commit diff
path: root/tests/util/caches/test_descriptors.py (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Add missing type hints to test.util.caches (#14529)Patrick Cloke2022-11-221-8/+14
|
* Remove unused `@lru_cache` decorator (#13595)Nick Mills-Barrett2022-10-251-36/+4
| | | | | | | * Remove unused `@lru_cache` decorator Spotted this working on something else. Co-authored-by: David Robertson <davidr@element.io>
* Bump flake8-bugbear from 21.3.2 to 22.9.23 (#14042)dependabot[bot]2022-10-191-1/+1
| | | | | 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 `have_seen_event` cache not being invalidated (#13863)Eric Eastwood2022-09-271-1/+32
| | | | | | | | | | | | | | | | | | | | | 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 cancellation support to `@cached` and `@cachedList` decorators (#12183)Sean Quah2022-03-141-2/+145
| | | | | | | | These decorators mostly support cancellation already. Add cancellation tests and fix use of finished logging contexts by delaying cancellation, as suggested by @erikjohnston. Signed-off-by: Sean Quah <seanq@element.io>
* Allow for ignoring some arguments when caching. (#12189)Patrick Cloke2022-03-091-3/+81
| | | | | * `@cached` can now take an `uncached_args` which is an iterable of names to not use in the cache key. * Requires `@cached`, @cachedList` and `@lru_cache` to use keyword arguments for clarity. * Asserts that keyword-only arguments in cached functions are not accepted. (I tested this briefly and I don't believe this works properly.)
* Fix 'Unhandled error in Deferred' (#12089)Richard van der Hoff2022-03-011-5/+5
| | | | | | | | | | | | | * Fix 'Unhandled error in Deferred' Fixes a CRITICAL "Unhandled error in Deferred" log message which happened when a function wrapped with `@cachedList` failed * Minor optimisation to cachedListDescriptor we can avoid re-using `missing`, which saves looking up entries in `deferreds_map`, and means we don't need to copy it. * Improve type annotation on CachedListDescriptor
* Replace assertEquals and friends with non-deprecated versions. (#12092)Patrick Cloke2022-02-281-35/+35
|
* Additional test for `cachedList` (#11246)Richard van der Hoff2021-11-041-0/+43
| | | | | I was trying to understand how `cachedList` works, and ended up writing this extra test. I figure we may as well keep it.
* Use inline type hints in `tests/` (#10350)Jonathan de Jong2021-07-131-1/+1
| | | | | | | | This PR is tantamount to running: python3.8 -m com2ann -v 6 tests/ (com2ann requires python 3.8 to run)
* Combine `LruCache.invalidate` and `invalidate_many` (#9973)Richard van der Hoff2021-05-271-3/+3
| | | | | | | | | | * 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
* Minor `@cachedList` enhancements (#9975)Richard van der Hoff2021-05-141-3/+14
| | | | | | - use a tuple rather than a list for the iterable that is passed into the wrapped function, for performance - test that we can pass an iterable and that keys are correctly deduped.
* Merge branch 'master' into developAndrew Morgan2021-04-201-4/+2
|\
| * Always use the name as the log ID. (#9829)Patrick Cloke2021-04-201-4/+2
| | | | | | | | | | As far as I can tell our logging contexts are meant to log the request ID, or sometimes the request ID followed by a suffix (this is generally stored in the name field of LoggingContext). There's also code to log the name@memory location, but I'm not sure this is ever used. This simplifies the code paths to require every logging context to have a name and use that in logging. For sub-contexts (created via nested_logging_contexts, defer_to_threadpool, Measure) we use the current context's str (which becomes their name or the string "sentinel") and then potentially modify that (e.g. add a suffix).
* | 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>`
* Use mock from the stdlib. (#9772)Patrick Cloke2021-04-091-2/+1
|
* Record more information into structured logs. (#9654)Patrick Cloke2021-04-081-4/+3
| | | | Records additional request information into the structured logs, e.g. the requester, IP address, etc.
* Update black, and run auto formatting over the codebase (#9381)Eric Eastwood2021-02-161-7/+5
| | | | | | | - 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
* Implement and use an @lru_cache decorator (#8595)Richard van der Hoff2020-10-301-1/+59
| | | We don't always need the full power of a DeferredCache.
* Add some more testsRichard van der Hoff2020-10-211-0/+52
|
* Push some deferred wrangling down into DeferredCacheRichard van der Hoff2020-10-211-3/+2
|
* Combine the two sets of tests for CacheDescriptorRichard van der Hoff2020-10-211-0/+230
|
* move DeferredCache into its own moduleRichard van der Hoff2020-10-141-44/+0
|
* Rename Cache->DeferredCacheRichard van der Hoff2020-10-141-2/+2
|
* Stop sub-classing object (#8249)Patrick Cloke2020-09-041-10/+10
|
* Remove the unused inlineCallbacks code-paths in the caching code (#8119)Patrick Cloke2020-08-191-6/+6
|
* Clean up some LoggingContext stuff (#7120)Richard van der Hoff2020-03-241-10/+12
| | | | | | | | | | | | | | | | | | | | | | | * Pull Sentinel out of LoggingContext ... and drop a few unnecessary references to it * Factor out LoggingContext.current_context move `current_context` and `set_context` out to top-level functions. Mostly this means that I can more easily trace what's actually referring to LoggingContext, but I think it's generally neater. * move copy-to-parent into `stop` this really just makes `start` and `stop` more symetric. It also means that it behaves correctly if you manually `set_log_context` rather than using the context manager. * Replace `LoggingContext.alive` with `finished` Turn `alive` into `finished` and make it a bit better defined.
* Make ObservableDeferred.observe() always return deferred.Erik Johnston2019-10-301-2/+2
| | | | | | | This makes it easier to use in an async/await world. Also fixes a bug where cache descriptors would occaisonally return a raw value rather than a deferred.
* Quick fix to ensure cache descriptors always return deferredsErik Johnston2019-10-281-2/+2
|
* Fix some error cases in the caching layer. (#5749)Richard van der Hoff2019-07-251-3/+87
| | | | | | | There was some inconsistent behaviour in the caching layer around how exceptions were handled - particularly synchronously-thrown ones. This seems to be most easily handled by pushing the creation of ObservableDeferreds down from CacheDescriptor to the Cache.
* Replace returnValue with return (#5736)Amber Brown2019-07-231-4/+4
|
* Move logging utilities out of the side drawer of util/ and into logging/ (#5606)Amber Brown2019-07-041-29/+20
|
* Run Black. (#5482)Amber Brown2019-06-201-30/+30
|
* Run black.black2018-08-101-26/+20
|
* fix invalidationRichard van der Hoff2018-07-271-1/+41
|
* Rewrite cache list decoratorRichard van der Hoff2018-07-271-0/+61
| | | | | Because it was complicated and annoyed me. I suspect this will be more efficient too.
* run isortAmber Brown2018-07-091-2/+5
|
* Reinstate lost run_on_reactor in unit testRichard van der Hoff2018-07-041-2/+15
| | | | | | | | a61738b removed a call to run_on_reactor from a unit test, but that call was doing something useful, in making the function in question asynchronous. Reinstate the call and add a check that we are testing what we wanted to be testing.
* Remove run_on_reactor (#3395)Amber Brown2018-06-141-2/+0
|
* Fix overzealous cache invalidationRichard van der Hoff2018-04-051-0/+46
| | | | | Fixes an issue where a cache invalidation would invalidate *all* pending entries, rather than just the entry that we intended to invalidate.
* Fix up testsErik Johnston2017-03-301-0/+38
|
* Fix the logcontext handling in the cache wrappers (#2077)Richard van der Hoff2017-03-301-0/+91
| | | | | | | The cache wrappers had a habit of leaking the logcontext into the reactor while the lookup function was running, and then not restoring it correctly when the lookup function had completed. It's all the fault of `preserve_context_over_{fn,deferred}` which are basically a bit broken.
* Fix caching of remote servers' signature keysRichard van der Hoff2017-03-221-0/+86
The `@cached` decorator on `KeyStore._get_server_verify_key` was missing its `num_args` parameter, which meant that it was returning the wrong key for any server which had more than one recorded key. By way of a fix, change the default for `num_args` to be *all* arguments. To implement that, factor out a common base class for `CacheDescriptor` and `CacheListDescriptor`.