Browse Source

neon: Fix loading data from cache

pull/74/head
jld3103 2 years ago
parent
commit
d69cac4554
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 2
      packages/neon/lib/src/blocs/apps.dart
  2. 2
      packages/neon/lib/src/blocs/capabilities.dart
  3. 2
      packages/neon/lib/src/blocs/user_details.dart
  4. 2
      packages/neon/lib/src/blocs/user_status.dart
  5. 19
      packages/neon/lib/src/utils/request_manager.dart

2
packages/neon/lib/src/blocs/apps.dart

@ -106,7 +106,7 @@ class AppsBloc extends $AppsBloc {
'apps-apps', 'apps-apps',
() async => _account.client.core.getNavigationApps(), () async => _account.client.core.getNavigationApps(),
(final response) => response.ocs!.data!, (final response) => response.ocs!.data!,
preloadCache: true, previousData: _appsSubject.valueOrNull?.data,
) )
.listen(_appsSubject.add); .listen(_appsSubject.add);
} }

2
packages/neon/lib/src/blocs/capabilities.dart

@ -37,7 +37,7 @@ class CapabilitiesBloc extends $CapabilitiesBloc {
'capabilities', 'capabilities',
() async => _client.core.getCapabilities(), () async => _client.core.getCapabilities(),
(final response) => response.ocs!.data!, (final response) => response.ocs!.data!,
preloadCache: true, previousData: _capabilitiesSubject.valueOrNull?.data,
) )
.listen(_capabilitiesSubject.add); .listen(_capabilitiesSubject.add);
} }

2
packages/neon/lib/src/blocs/user_details.dart

@ -34,7 +34,7 @@ class UserDetailsBloc extends $UserDetailsBloc {
'user-details', 'user-details',
() async => _client.provisioningApi.getCurrentUser(), () async => _client.provisioningApi.getCurrentUser(),
(final response) => response.ocs!.data!, (final response) => response.ocs!.data!,
preloadCache: true, previousData: _userDetailsSubject.valueOrNull?.data,
) )
.listen(_userDetailsSubject.add); .listen(_userDetailsSubject.add);
} }

2
packages/neon/lib/src/blocs/user_status.dart

@ -45,7 +45,7 @@ class UserStatusBloc extends $UserStatusBloc {
'user-status', 'user-status',
() async => _account.client.userStatus.getStatus(), () async => _account.client.userStatus.getStatus(),
(final response) => response.ocs?.data?.userStatus, (final response) => response.ocs?.data?.userStatus,
preloadCache: true, previousData: _userStatusSubject.valueOrNull?.data,
) )
.listen(_userStatusSubject.add); .listen(_userStatusSubject.add);
} }

19
packages/neon/lib/src/utils/request_manager.dart

@ -33,10 +33,8 @@ class RequestManager {
final String k, final String k,
final Future<R> Function() call, final Future<R> Function() call,
final T Function(R) unwrap, { final T Function(R) unwrap, {
final bool preloadCache = false, required final T? previousData,
final bool preferCache = false,
final bool disableTimeout = false, final bool disableTimeout = false,
final T? previousData,
}) async* { }) async* {
yield* _wrap<T, R>( yield* _wrap<T, R>(
clientID, clientID,
@ -45,8 +43,6 @@ class RequestManager {
(final d) => deserialize<R>(json.decode(d)), (final d) => deserialize<R>(json.decode(d)),
call, call,
unwrap: unwrap, unwrap: unwrap,
preloadCache: preloadCache,
preferCache: preferCache,
previousData: previousData, previousData: previousData,
disableTimeout: disableTimeout, disableTimeout: disableTimeout,
); );
@ -56,7 +52,6 @@ class RequestManager {
final String clientID, final String clientID,
final String k, final String k,
final Future<Uint8List> Function() call, { final Future<Uint8List> Function() call, {
final bool preloadCache = false,
final bool preferCache = false, final bool preferCache = false,
final bool disableTimeout = false, final bool disableTimeout = false,
final Uint8List? previousData, final Uint8List? previousData,
@ -67,7 +62,6 @@ class RequestManager {
(final s) => base64.encode(s), (final s) => base64.encode(s),
(final d) => base64.decode(d), (final d) => base64.decode(d),
call, call,
preloadCache: preloadCache,
preferCache: preferCache, preferCache: preferCache,
previousData: previousData, previousData: previousData,
disableTimeout: disableTimeout, disableTimeout: disableTimeout,
@ -77,7 +71,6 @@ class RequestManager {
final String clientID, final String clientID,
final String k, final String k,
final Future<String> Function() call, { final Future<String> Function() call, {
final bool preloadCache = false,
final bool preferCache = false, final bool preferCache = false,
final bool disableTimeout = false, final bool disableTimeout = false,
final String? previousData, final String? previousData,
@ -88,7 +81,6 @@ class RequestManager {
(final s) => s, (final s) => s,
(final d) => d, (final d) => d,
call, call,
preloadCache: preloadCache,
preferCache: preferCache, preferCache: preferCache,
previousData: previousData, previousData: previousData,
disableTimeout: disableTimeout, disableTimeout: disableTimeout,
@ -99,7 +91,6 @@ class RequestManager {
final String Function(R) serialize, final String Function(R) serialize,
final R Function(String) deserialize, final R Function(String) deserialize,
final Future<R> Function() call, { final Future<R> Function() call, {
final bool preloadCache = false,
final bool preferCache = false, final bool preferCache = false,
final bool disableTimeout = false, final bool disableTimeout = false,
T Function(R)? unwrap, T Function(R)? unwrap,
@ -117,14 +108,14 @@ class RequestManager {
_print('[Request]: $k'); _print('[Request]: $k');
if ((preferCache || preloadCache) && cache != null && await cache!.has(key)) { if (cache != null && await cache!.has(key)) {
_print('[Cache]: $k'); _print('[Cache]: $k');
final s = unwrap(deserialize((await cache!.get(key))!)); final s = unwrap(deserialize((await cache!.get(key))!));
if (preloadCache) { if (preferCache) {
yield ResultCached(s, loading: true);
} else {
yield Result.success(s); yield Result.success(s);
return; return;
} else {
yield ResultCached(s, loading: true);
} }
} }

Loading…
Cancel
Save