Skip to content

Conversation

@krille-chan
Copy link
Contributor

@krille-chan krille-chan commented Jan 2, 2026

This caches multiple static
content requests in the database
with a unified and simple way
which reduces in memory
state.

closes https://github.com/famedly/product-management/issues/2358

This simplifies some things a lot but also introduces an inconveniency: You can no longer access the wellKnown cache in and synchronious way by client.wellKnown but have to always await client.getWellKnown(). IMO this is definitely worth it to get rid of the state and win simplicity and also have these static content stored in the exactly same manner:

  • Well-Known
  • Auth Metadata
  • Versions
  • Client Config

This caches multiple static
content requests in the database
with a unified and simple way
which reduces in memory
state.
@codecov
Copy link

codecov bot commented Jan 2, 2026

Codecov Report

❌ Patch coverage is 88.57143% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.59%. Comparing base (da1e7c6) to head (b46faa0).

Files with missing lines Patch % Lines
lib/src/utils/request_and_cache.dart 70.00% 3 Missing ⚠️
lib/src/client.dart 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2216      +/-   ##
==========================================
+ Coverage   57.53%   57.59%   +0.05%     
==========================================
  Files         153      153              
  Lines       19476    19479       +3     
==========================================
+ Hits        11205    11218      +13     
+ Misses       8271     8261      -10     
Files with missing lines Coverage Δ
lib/src/database/database_api.dart 0.00% <ø> (ø)
lib/src/database/matrix_sdk_database.dart 91.03% <100.00%> (+0.17%) ⬆️
lib/src/voip/utils/famedly_call_extension.dart 60.95% <100.00%> (ø)
lib/src/client.dart 77.29% <94.11%> (-0.17%) ⬇️
lib/src/utils/request_and_cache.dart 70.00% <70.00%> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update da1e7c6...b46faa0. Read the comment docs.

stackTrace,
);

if (cachedResponse != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it really okay to return the user an expired cached data when a new request fails? I personally think we should just rethrow directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would say it is better for the UX. We are doing this in a lot of other places already. And without WellKnown information for example most features of our app are not functional. And as these things very rarely change at all (maybe once a year or so or maybe even never?) having an "expired" result shouldn't be that bad.

Copy link
Contributor

Choose a reason for hiding this comment

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

What if there's a config for blocking calls in well known and its changed on server side. Let's say the app fails to fetch this due to some internet issue and gives the old cached data. Later let's say the internet recovers but the app gets well known only on app startup so it has old data. This will make the user able to make calls even if it's changed on server side.

Comment on lines 614 to 631
/*async {
final wellKnownResponse = await httpClient.get(
Uri.https(
userID?.domain ?? homeserver!.host,
'/.well-known/matrix/client',
),
);
final wellKnown = DiscoveryInformation.fromJson(
jsonDecode(utf8.decode(wellKnownResponse.bodyBytes))
as Map<String, Object?>,
);
// do not reset the well known here, so super call
super.homeserver = wellKnown.mHomeserver.baseUrl.stripTrailingSlash();
_wellKnown = wellKnown;
await database.storeWellKnown(wellKnown);
return wellKnown;
}
}*/
Copy link
Contributor

Choose a reason for hiding this comment

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

can we remove this commented section?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah good catch!


Future<bool> authenticatedMediaSupported() async {
return (await versionsResponse).versions.any(
return (await getVersions()).versions.any(
Copy link
Contributor

Choose a reason for hiding this comment

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

we could have a variable for await getVersions() so that it's not called twice

if (discoveryInformation == null) {
return _clientBox.delete('discovery_information');
}
Future<void> cacheCustomObject(String cacheKey, Map<String, Object?> object) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to make sure that all these values are also cleared on clearCache() method in the same class. Maybe add some tests too?

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.

3 participants