feat(event cache): write updates from the event cache to storage #4347
+372
−138
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is one direction1 of interacting between the event cache and the storage backend. I think this is fine design… as long as we don't have any other process writing into the cache, in which case we'll need to reset at different boundaries.
The main idea in this PR is to use
RoomEventCacheState::with_events_mut(func: impl FnMut(&mut RoomEvents))
to perform any write to the underlyingRoomEvent
data structure. The function takes care of maintaining the storage, after updates have been performed.Additionally: this behavior isn't enabled by default; callers have to call
EventCache::enable_storage()
when they start using the event cache.I've put the
RoomEventCacheState
data structure in a private module, so that even the same module can't access its private fields, and we don't make mistakes by accidentally misusingevents
.Part of #3280. Split and reworked from #4308.
Footnotes
not the band ↩