Skip to content

feat(sdk): Create ThreadEventCacheState#6280

Open
Hywan wants to merge 7 commits intomatrix-org:mainfrom
Hywan:chore-sdk-event-cache-thread-state
Open

feat(sdk): Create ThreadEventCacheState#6280
Hywan wants to merge 7 commits intomatrix-org:mainfrom
Hywan:chore-sdk-event-cache-thread-state

Conversation

@Hywan
Copy link
Member

@Hywan Hywan commented Mar 12, 2026

This patch updates ThreadEventCache to contain a ThreadEventCacheInner. Then, it creates ThreadEventCacheState (with no store support for the moment, but at least all the lock, reload and reset logic is here!). Finally it updates ThreadPagination to own a ThreadEventCacheInner instead of a RoomEventCacheInner (finally!).



  • I've documented the public API Changes in the appropriate CHANGELOG.md files.
  • This PR was made with the help of AI.

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 85.76389% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.90%. Comparing base (acda2e8) to head (94dbe71).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
.../matrix-sdk/src/event_cache/caches/thread/state.rs 86.71% 9 Missing and 8 partials ⚠️
...es/matrix-sdk/src/event_cache/caches/thread/mod.rs 79.71% 5 Missing and 9 partials ⚠️
...ix-sdk/src/event_cache/caches/thread/pagination.rs 86.79% 3 Missing and 4 partials ⚠️
...es/matrix-sdk/src/event_cache/caches/room/state.rs 90.90% 0 Missing and 2 partials ⚠️
...ates/matrix-sdk/src/event_cache/caches/room/mod.rs 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6280      +/-   ##
==========================================
- Coverage   89.91%   89.90%   -0.02%     
==========================================
  Files         374      375       +1     
  Lines      102613   102703      +90     
  Branches   102613   102703      +90     
==========================================
+ Hits        92267    92337      +70     
- Misses       6783     6786       +3     
- Partials     3563     3580      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 12, 2026

Merging this PR will not alter performance

✅ 50 untouched benchmarks


Comparing Hywan:chore-sdk-event-cache-thread-state (94dbe71) with main (acda2e8)

Open in CodSpeed

@Hywan Hywan force-pushed the chore-sdk-event-cache-thread-state branch from 581d2f8 to 9b67ac4 Compare March 13, 2026 10:15
Hywan added a commit to Hywan/matrix-rust-sdk that referenced this pull request Mar 13, 2026
Hywan added 6 commits March 13, 2026 11:30
This patch moves up the `has_new_gap` definition to clarify the code
even more.
This patch creates `ThreadEventCacheInner` so that `ThreadEventCache`
can be shallow cloned (which will be useful for `ThreadPagination`).
That's also the first step to introduce `ThreadEventCacheState`!
This patch creates the `ThreadEventCacheState` type. It uses
`caches::lock::StateLock`, just like `RoomEventCacheState`. It allows
to have the `read()` and `write()` method to access the state, and to
reload it when necessary, see the `caches::lock::Store` implementation.

This patch thus creates `ThreadEventCacheStateLockReadGuard` and
`ThreadEventCacheStateLockWriteGuard`. The methods touching the state in
`ThreadEventCacheInner` are moved to these lock types.

They are purely code moves (plus changes to reach the correct data): no
change in the semantics.
This patch adds the `weak_room: WeakRoom` field to
`ThreadEventCacheInner`. This is a prerequisite to have
`ThreadPagination` uses `ThreadEventCacheInner` instead of
`RoomEventCacheInner`!
…y `ThreadEventCacheInner`.

This patch updates `ThreadPagination` to hold a `ThreadEventCacheInner`
instead of a `RoomEventCacheInner`! It makes more sense and it
splits/isolates the types even more.

`RoomEventCache::thread_pagination` is now async and returns a
`Result<ThreadPagination>` because it needs to load its state to fetch
a `ThreadEventCache`. Later, accessing a thread wouldn't happen in
`RoomEventCache` but in `Caches`, one step at a time.
@Hywan Hywan force-pushed the chore-sdk-event-cache-thread-state branch from 22fea47 to 10e48e1 Compare March 13, 2026 10:42
@Hywan Hywan marked this pull request as ready for review March 13, 2026 12:42
@Hywan Hywan requested a review from a team as a code owner March 13, 2026 12:42
@Hywan Hywan requested review from stefanceriu and removed request for a team March 13, 2026 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant