mirror of
https://github.com/immich-app/immich.git
synced 2025-01-04 02:46:47 +01:00
fix(mobile): fix cache invalidation on logout (#1030)
await all the cache-invalidation operations during logout and catch errors to actually perform all operations.
This commit is contained in:
parent
024177515d
commit
d82dec9773
4 changed files with 18 additions and 11 deletions
|
@ -30,11 +30,11 @@ class AssetService {
|
||||||
AssetService(this._apiService, this._backupService, this._backgroundService);
|
AssetService(this._apiService, this._backupService, this._backgroundService);
|
||||||
|
|
||||||
/// Returns `null` if the server state did not change, else list of assets
|
/// Returns `null` if the server state did not change, else list of assets
|
||||||
Future<List<Asset>?> getRemoteAssets() async {
|
Future<List<Asset>?> getRemoteAssets({required bool hasCache}) async {
|
||||||
final Box box = Hive.box(userInfoBox);
|
final Box box = Hive.box(userInfoBox);
|
||||||
final Pair<List<AssetResponseDto>, String?>? remote = await _apiService
|
final Pair<List<AssetResponseDto>, String?>? remote = await _apiService
|
||||||
.assetApi
|
.assetApi
|
||||||
.getAllAssetsWithETag(eTag: box.get(assetEtagKey));
|
.getAllAssetsWithETag(eTag: hasCache ? box.get(assetEtagKey) : null);
|
||||||
if (remote == null) {
|
if (remote == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,11 +101,14 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> logout() async {
|
Future<bool> logout() async {
|
||||||
Hive.box(userInfoBox).delete(accessTokenKey);
|
|
||||||
state = state.copyWith(isAuthenticated: false);
|
state = state.copyWith(isAuthenticated: false);
|
||||||
_assetCacheService.invalidate();
|
await Future.wait([
|
||||||
_albumCacheService.invalidate();
|
Hive.box(userInfoBox).delete(accessTokenKey),
|
||||||
_sharedAlbumCacheService.invalidate();
|
Hive.box(userInfoBox).delete(assetEtagKey),
|
||||||
|
_assetCacheService.invalidate(),
|
||||||
|
_albumCacheService.invalidate(),
|
||||||
|
_sharedAlbumCacheService.invalidate(),
|
||||||
|
]);
|
||||||
|
|
||||||
// Remove login info from local storage
|
// Remove login info from local storage
|
||||||
var loginInfo =
|
var loginInfo =
|
||||||
|
@ -115,7 +118,7 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
|
||||||
loginInfo.password = "";
|
loginInfo.password = "";
|
||||||
loginInfo.isSaveLogin = false;
|
loginInfo.isSaveLogin = false;
|
||||||
|
|
||||||
Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox).put(
|
await Hive.box<HiveSavedLoginInfo>(hiveLoginInfoBox).put(
|
||||||
savedLoginInfoKey,
|
savedLoginInfoKey,
|
||||||
loginInfo,
|
loginInfo,
|
||||||
);
|
);
|
||||||
|
|
|
@ -38,7 +38,7 @@ class AssetNotifier extends StateNotifier<List<Asset>> {
|
||||||
final bool isCacheValid = await _assetCacheService.isValid();
|
final bool isCacheValid = await _assetCacheService.isValid();
|
||||||
stopwatch.start();
|
stopwatch.start();
|
||||||
final localTask = _assetService.getLocalAssets(urgent: !isCacheValid);
|
final localTask = _assetService.getLocalAssets(urgent: !isCacheValid);
|
||||||
final remoteTask = _assetService.getRemoteAssets();
|
final remoteTask = _assetService.getRemoteAssets(hasCache: isCacheValid);
|
||||||
if (isCacheValid && state.isEmpty) {
|
if (isCacheValid && state.isEmpty) {
|
||||||
state = await _assetCacheService.get();
|
state = await _assetCacheService.get();
|
||||||
log.info(
|
log.info(
|
||||||
|
|
|
@ -23,8 +23,12 @@ abstract class JsonCache<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> invalidate() async {
|
Future<void> invalidate() async {
|
||||||
final file = await _getCacheFile();
|
try {
|
||||||
await file.delete();
|
final file = await _getCacheFile();
|
||||||
|
await file.delete();
|
||||||
|
} on FileSystemException {
|
||||||
|
// file is already deleted
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> putRawData(dynamic data) async {
|
Future<void> putRawData(dynamic data) async {
|
||||||
|
@ -46,4 +50,4 @@ abstract class JsonCache<T> {
|
||||||
|
|
||||||
void put(T data);
|
void put(T data);
|
||||||
Future<T> get();
|
Future<T> get();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue