mirror of
https://github.com/element-hq/synapse.git
synced 2026-11-05 13:17:54 +00:00
The first Rust database function to get a cache, and the first Python `@cached` function to be replaced by one. The Rust `/versions` handler calls `Store::is_feature_enabled_for_user` on every authenticated request, and until now each call ran a query. The Python `is_feature_enabled` had a cache of the same rows under another name, which every writer would have had to invalidate alongside. Now there is one cache, keyed on `(user_id, feature)`, and both sides read through it. The main datastore builds the Rust `Store` in its `__init__`, over its own `db_pool`, and `hs.get_rust_store()` hands it to the Rust handlers: the datastore owns the store, the handlers borrow it. The store's `is_feature_enabled_for_user` reaches Python as a callable cache object, bound on the datastore under that name. Calling it answers a hit with an already-fired Deferred, without leaving the reactor thread, and only a miss goes through tokio. Being a `RustCache`, it is also what `_invalidate_cache_and_stream`, replication and `register_cache` take, so `set_features_for_user` invalidates it with the one call it already made, and the name is spelled once in Rust, where the cache is built. `is_feature_enabled` keeps its global-config short cut in Python and delegates the per-user lookup. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ULdieJyQoHNzeHq42H2M1p