fix: dedup /versions calls

This commit is contained in:
td 2024-08-23 16:30:56 +02:00
parent 5f85acb7f0
commit d9681d552e
No known key found for this signature in database
GPG Key ID: 62A30523D4D6CE28
2 changed files with 10 additions and 3 deletions

View File

@ -93,6 +93,7 @@ class FakeMatrixApi extends BaseClient {
Set<String> servers = {
'https://fakeserver.notexisting',
'https://fakeserver.notexisting:1337',
'https://fakeserverpriortoauthmedia.notexisting'
};

View File

@ -526,7 +526,7 @@ class Client extends MatrixApi {
}
// Check if server supports at least one supported version
final versions = _versionsCache = await getVersions();
final versions = await getVersions();
if (!versions.versions
.any((version) => supportedVersions.contains(version))) {
throw BadServerVersionsException(
@ -1199,10 +1199,11 @@ class Client extends MatrixApi {
_archivedRooms.add(ArchivedRoom(room: archivedRoom, timeline: timeline));
}
GetVersionsResponse? _versionsCache;
final _versionsCache =
AsyncCache<GetVersionsResponse>(const Duration(hours: 1));
Future<bool> authenticatedMediaSupported() async {
final versionsResponse = _versionsCache ??= await getVersions();
final versionsResponse = await _versionsCache.fetch(() => getVersions());
return versionsResponse.versions.any(
(v) => isVersionGreaterThanOrEqualTo(v, 'v1.11'),
) ||
@ -1870,7 +1871,12 @@ class Client extends MatrixApi {
}
_groupCallSessionId = randomAlpha(12);
/// while I would like to move these to a onLoginStateChanged stream listener
/// that might be too much overhead and you don't have any use of these
/// when you are logged out anyway. So we just invalidate them on next login
_serverConfigCache.invalidate();
_versionsCache.invalidate();
final account = await this.database?.getClient(clientName);
newRefreshToken ??= account?.tryGet<String>('refresh_token');