Skip to content

Sliding Sync: Make sure we get up-to-date information from get_sliding_sync_rooms_for_user(...) #17692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented Sep 10, 2024

Make sure we get up-to-date information from get_sliding_sync_rooms_for_user(...). We need to bust the get_sliding_sync_rooms_for_user cache when the room encryption is updated and any other field that is used in the query.

Follow-up to #17630

TODO

  • Bust cache for membership change (cross-reference get_rooms_for_user)
  • Bust cache for room encryption (cross-reference get_room_encryption)
  • Bust cache for forgotten (cross-reference did_forget/get_forgotten_rooms_for_user)

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct
    (run the linters)

Make sure we get up-to-date information from `get_sliding_sync_rooms_for_user(...)`
@@ -483,6 +488,7 @@ def _invalidate_caches_for_room(self, room_id: str) -> None:
self._attempt_to_invalidate_cache("get_room_version_id", (room_id,))
self._attempt_to_invalidate_cache("get_room_type", (room_id,))
self._attempt_to_invalidate_cache("get_room_encryption", (room_id,))
self._attempt_to_invalidate_cache("get_sliding_sync_rooms_for_user", None)
Copy link
Contributor Author

@MadLittleMods MadLittleMods Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_sliding_sync_rooms_for_user(...) doesn't cache very well because we have to bust it whenever state in any room changes. Is it even worth caching it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I discovered this in the first place is because I tried adding COALESCE(j.event_stream_ordering, m.event_stream_ordering) for sorting and discovered that get_sliding_sync_rooms_for_user(...) was returning a bunch of cached values. And busting the cache for any event sent on the homeserver just doesn't make sense to do.

But busting the cache when any state across the homeserver seems just as bad.

@@ -275,6 +275,9 @@ def _process_event_stream_row(self, token: int, row: EventsStreamRow) -> None:
self._attempt_to_invalidate_cache(
"get_room_encryption", (data.room_id,)
)
self._attempt_to_invalidate_cache(
"get_sliding_sync_rooms_for_user", None
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Busting the cache wherever we bust it for get_room_encryption already

@@ -1348,6 +1348,9 @@ def f(txn: LoggingTransaction) -> None:
self._invalidate_cache_and_stream(
txn, self.get_forgotten_rooms_for_user, (user_id,)
)
self._invalidate_cache_and_stream(
txn, self.get_sliding_sync_rooms_for_user, (user_id,)
)
Copy link
Contributor Author

@MadLittleMods MadLittleMods Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Busting the cache whenever we bust the cache for did_forget/get_forgotten_rooms_for_user

@MadLittleMods MadLittleMods changed the title Make sure we get up-to-date information from get_sliding_sync_rooms_for_user(...) Sliding Sync: Make sure we get up-to-date information from get_sliding_sync_rooms_for_user(...) Sep 10, 2024
},
}
}
response_body, from_token = self.do_sync(sync_body, tok=user1_tok)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, just updating to use the do_sync helper

@@ -831,6 +820,98 @@ def test_filter_regardless_of_membership_server_left_room(self) -> None:
],
)

def test_filter_is_encrypted_up_to_date(self) -> None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New tests

@MadLittleMods MadLittleMods marked this pull request as ready for review September 10, 2024 23:17
@MadLittleMods MadLittleMods requested a review from a team as a code owner September 10, 2024 23:17
@MadLittleMods MadLittleMods merged commit e4a1f27 into develop Sep 11, 2024
39 checks passed
@MadLittleMods MadLittleMods deleted the madlittlemods/get_sliding_sync_rooms_for_user-bust-cache branch September 11, 2024 17:13
@MadLittleMods
Copy link
Contributor Author

Thanks for the review @erikjohnston 🐕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants