fix: archive takes 2 minutes to update
In Synapse 1.62.0 the default cache duration of initial sync responses was changed to 2 minutes. That means our archive calls might return stale data. Since different sync timeouts bust through the cache, we make use of that to be able to load the new archive immediately. fixes https://gitlab.com/famedly/company/frontend/famedly-web/-/issues/634
This commit is contained in:
parent
03826e6d47
commit
2c3194b823
|
|
@ -870,14 +870,25 @@ class Client extends MatrixApi {
|
|||
return (await loadArchiveWithTimeline()).map((e) => e.room).toList();
|
||||
}
|
||||
|
||||
// Synapse caches sync responses. Documentation:
|
||||
// https://matrix-org.github.io/synapse/latest/usage/configuration/config_documentation.html#caches-and-associated-values
|
||||
// At the time of writing, the cache key consists of the following fields: user, timeout, since, filter_id,
|
||||
// full_state, device_id, last_ignore_accdata_streampos.
|
||||
// Since we can't pass a since token, the easiest field to vary is the timeout to bust through the synapse cache and
|
||||
// give us the actual currently left rooms. Since the timeout doesn't matter for initial sync, this should actually
|
||||
// not make any visible difference apart from properly fetching the cached rooms.
|
||||
int _archiveCacheBusterTimeout = 0;
|
||||
|
||||
/// Fetch the archived rooms from the server and return them as a list of
|
||||
/// [ArchivedRoom] objects containing the [Room] and the associated [Timeline].
|
||||
Future<List<ArchivedRoom>> loadArchiveWithTimeline() async {
|
||||
_archivedRooms.clear();
|
||||
final syncResp = await sync(
|
||||
filter: '{"room":{"include_leave":true,"timeline":{"limit":10}}}',
|
||||
timeout: 0,
|
||||
timeout: _archiveCacheBusterTimeout,
|
||||
);
|
||||
// wrap around and hope there are not more than 30 leaves in 2 minutes :)
|
||||
_archiveCacheBusterTimeout = (_archiveCacheBusterTimeout + 1) % 30;
|
||||
|
||||
final leave = syncResp.rooms?.leave;
|
||||
if (leave != null) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue