fix: Invalidate space hierarchy cache on room join/leave events #1524

Closed
javif89 wants to merge 2 commits from javif89/continuwuity:fix/invalidate-hierarchy-cache-on-room-event into main
First-time contributor

This pull request adds SpaceRoomHierarchy cache invalidation on room join/leave events.

This change should prevent potentially dead rooms from showing up in clients, and make it easier
to make decisions based on a room's member count returned from the /[room id]/hierarchy endpoint.

I moved the roomid_spacehierarchy_cache up a level to the state_cache so it could be accessed in update_joined_count.
Otherwise we would have to invalidate the cache in any other spot where the member count might change.

Closes #1522

Pull request checklist:

  • This pull request targets the main branch, and the branch is named something other than
    main.
  • I have written an appropriate pull request title and my description is clear.
  • I understand I am responsible for the contents of this pull request.
  • I have followed the contributing guidelines:
This pull request adds `SpaceRoomHierarchy` cache invalidation on room join/leave events. This change should prevent potentially dead rooms from showing up in clients, and make it easier to make decisions based on a room's member count returned from the `/[room id]/hierarchy` endpoint. I moved the `roomid_spacehierarchy_cache` up a level to the `state_cache` so it could be accessed in `update_joined_count`. Otherwise we would have to invalidate the cache in any other spot where the member count might change. Closes #1522 **Pull request checklist:** - [x] This pull request targets the `main` branch, and the branch is named something other than `main`. - [x] I have written an appropriate pull request title and my description is clear. - [x] I understand I am responsible for the contents of this pull request. - I have followed the [contributing guidelines][c1]: - [x] My contribution follows the [code style][c2], if applicable. - [x] I ran [pre-commit checks][c1pc] before opening/drafting this pull request. - [x] I have [tested my contribution][c1t] (or proof-read it for documentation-only changes) myself, if applicable. This includes ensuring code compiles. - [x] My commit messages follow the [commit message format][c1cm] and are descriptive. - [ ] I have written a [news fragment][n1] for this PR, if applicable<!--(can be done after hitting open!)-->. [c1]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md [c2]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/docs/development/code_style.mdx [c1pc]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#pre-commit-checks [c1t]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#running-tests-locally [c1cm]: https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/CONTRIBUTING.md#commit-messages [n1]: https://towncrier.readthedocs.io/en/stable/tutorial.html#creating-news-fragments
ginger left a comment

a few preliminary thoughts

a few preliminary thoughts
@ -40,7 +40,7 @@ repos:
hooks:
- id: cargo-fmt
name: cargo fmt
entry: cargo +nightly fmt --
Owner

this is supposed to use nightly

this is supposed to use nightly
Author
First-time contributor

Reverted 👍

Reverted 👍
nex marked this conversation as resolved
@ -21,8 +21,28 @@
pkgs.liburing
pkgs.rust-jemalloc-sys-unprefixed
rocksdbAllFeatures
# Pre commit support
Owner

these nix changes should go in their own PR

these nix changes should go in their own PR
Author
First-time contributor

Reverted

Reverted
nex marked this conversation as resolved
javif89 changed title from WIP: fix: Invalidate space hierarchy cache on room join/leave events to fix: Invalidate space hierarchy cache on room join/leave events 2026-03-11 21:07:14 +00:00
javif89 requested review from ginger 2026-03-12 16:10:58 +00:00
javif89 force-pushed fix/invalidate-hierarchy-cache-on-room-event from f402aaa84d
All checks were successful
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 2m56s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 16m4s
to 582e2aa9a8
All checks were successful
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 3m4s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 14m52s
2026-03-15 00:55:27 +00:00
Compare
@ -39,4 +38,3 @@
pub struct Service {
services: Services,
pub roomid_spacehierarchy_cache: Mutex<Cache>,
Owner

why was this cache moved to the state_cache service? I think it's more relevant to this service

why was this cache moved to the `state_cache` service? I think it's more relevant to this service
Owner

nevermind, I can't read

nevermind, I can't read
ginger marked this conversation as resolved
@ -54,12 +63,18 @@ struct Data {
}
type AppServiceInRoomCache = SyncRwLock<HashMap<OwnedRoomId, HashMap<String, bool>>>;
type SpaceHierarchyCache = Mutex<LruCache<OwnedRoomId, Option<CachedSpaceHierarchySummary>>>;
Owner
this may not need to be a Tokio mutex -- see https://docs.rs/tokio/latest/tokio/sync/struct.Mutex.html#which-kind-of-mutex-should-you-use
Author
First-time contributor

You might be right here. However, it was a tokio mutex before and I just moved the same logic, so I wouldn't want to change it as part of this PR since I don't know what downstream implications it would have.

Happy to work on that as part of a different task though if it would yield better performance.

You might be right here. However, [it was a tokio mutex before](https://forgejo.ellis.link/continuwuation/continuwuity/src/branch/main/src/service/rooms/spaces/mod.rs#L35) and I just moved the same logic, so I wouldn't want to change it as part of this PR since I don't know what downstream implications it would have. Happy to work on that as part of a different task though if it would yield better performance.
javif89 requested review from ginger 2026-03-18 00:30:13 +00:00
javif89 force-pushed fix/invalidate-hierarchy-cache-on-room-event from 582e2aa9a8
All checks were successful
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 3m4s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 14m52s
to 5c051c2c3d
All checks were successful
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 3m9s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 32m59s
2026-03-18 22:17:07 +00:00
Compare
javif89 force-pushed fix/invalidate-hierarchy-cache-on-room-event from 5c051c2c3d
All checks were successful
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 3m9s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 32m59s
to 556dd799e9
Some checks failed
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Check Changelog / Check for changelog (pull_request_target) Successful in 10s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 3m9s
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 25m32s
Checks / Changelog / Check changelog is added (pull_request_target) Failing after 34s
2026-03-30 02:45:07 +00:00
Compare
Owner

Closing this as it's superseded by the upcoming switch to upstream ruma, which includes a complete rewrite of the hierarchy endpoint.

Closing this as it's superseded by the upcoming switch to upstream ruma, which includes a complete rewrite of the hierarchy endpoint.
ginger closed this pull request 2026-04-13 14:21:45 +00:00
Owner
#1656
Some checks failed
Documentation / Build and Deploy Documentation (pull_request) Has been skipped
Check Changelog / Check for changelog (pull_request_target) Successful in 10s
Checks / Prek / Pre-commit & Formatting (pull_request) Successful in 3m9s
Required
Details
Checks / Prek / Clippy and Cargo Tests (pull_request) Successful in 25m32s
Required
Details
Checks / Changelog / Check changelog is added (pull_request_target) Failing after 34s
Required
Details

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
continuwuation/continuwuity!1524
No description provided.