mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-03 19:17:11 -05:00 
			
		
		
		
	Invalidation on logout and timing measurements
This commit is contained in:
		
							parent
							
								
									894eea739e
								
							
						
					
					
						commit
						75d8ca1306
					
				@ -19,6 +19,10 @@ class AssetCacheService {
 | 
				
			|||||||
        _cacheBox.get(assetListCachedAssets) is String;
 | 
					        _cacheBox.get(assetListCachedAssets) is String;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  void invalidate() {
 | 
				
			||||||
 | 
					    _cacheBox.clear();
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void putAssets(List<AssetResponseDto> assets) {
 | 
					  void putAssets(List<AssetResponseDto> assets) {
 | 
				
			||||||
    final mapList = assets.map((e) => e.toJson()).toList();
 | 
					    final mapList = assets.map((e) => e.toJson()).toList();
 | 
				
			||||||
    final jsonString = json.encode(mapList);
 | 
					    final jsonString = json.encode(mapList);
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
 | 
				
			|||||||
import 'package:hive/hive.dart';
 | 
					import 'package:hive/hive.dart';
 | 
				
			||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
 | 
					import 'package:hooks_riverpod/hooks_riverpod.dart';
 | 
				
			||||||
import 'package:immich_mobile/constants/hive_box.dart';
 | 
					import 'package:immich_mobile/constants/hive_box.dart';
 | 
				
			||||||
 | 
					import 'package:immich_mobile/modules/home/services/asset_cache.service.dart';
 | 
				
			||||||
import 'package:immich_mobile/modules/login/models/authentication_state.model.dart';
 | 
					import 'package:immich_mobile/modules/login/models/authentication_state.model.dart';
 | 
				
			||||||
import 'package:immich_mobile/modules/login/models/hive_saved_login_info.model.dart';
 | 
					import 'package:immich_mobile/modules/login/models/hive_saved_login_info.model.dart';
 | 
				
			||||||
import 'package:immich_mobile/modules/backup/services/backup.service.dart';
 | 
					import 'package:immich_mobile/modules/backup/services/backup.service.dart';
 | 
				
			||||||
@ -15,6 +16,7 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
 | 
				
			|||||||
    this._deviceInfoService,
 | 
					    this._deviceInfoService,
 | 
				
			||||||
    this._backupService,
 | 
					    this._backupService,
 | 
				
			||||||
    this._apiService,
 | 
					    this._apiService,
 | 
				
			||||||
 | 
					    this._assetCacheService,
 | 
				
			||||||
  ) : super(
 | 
					  ) : super(
 | 
				
			||||||
          AuthenticationState(
 | 
					          AuthenticationState(
 | 
				
			||||||
            deviceId: "",
 | 
					            deviceId: "",
 | 
				
			||||||
@ -41,6 +43,7 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
 | 
				
			|||||||
  final DeviceInfoService _deviceInfoService;
 | 
					  final DeviceInfoService _deviceInfoService;
 | 
				
			||||||
  final BackupService _backupService;
 | 
					  final BackupService _backupService;
 | 
				
			||||||
  final ApiService _apiService;
 | 
					  final ApiService _apiService;
 | 
				
			||||||
 | 
					  final AssetCacheService _assetCacheService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Future<bool> login(
 | 
					  Future<bool> login(
 | 
				
			||||||
    String email,
 | 
					    String email,
 | 
				
			||||||
@ -151,7 +154,7 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
 | 
				
			|||||||
  Future<bool> logout() async {
 | 
					  Future<bool> logout() async {
 | 
				
			||||||
    Hive.box(userInfoBox).delete(accessTokenKey);
 | 
					    Hive.box(userInfoBox).delete(accessTokenKey);
 | 
				
			||||||
    state = state.copyWith(isAuthenticated: false);
 | 
					    state = state.copyWith(isAuthenticated: false);
 | 
				
			||||||
 | 
					    _assetCacheService.invalidate();
 | 
				
			||||||
    return true;
 | 
					    return true;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -197,5 +200,6 @@ final authenticationProvider =
 | 
				
			|||||||
    ref.watch(deviceInfoServiceProvider),
 | 
					    ref.watch(deviceInfoServiceProvider),
 | 
				
			||||||
    ref.watch(backupServiceProvider),
 | 
					    ref.watch(backupServiceProvider),
 | 
				
			||||||
    ref.watch(apiServiceProvider),
 | 
					    ref.watch(apiServiceProvider),
 | 
				
			||||||
 | 
					    ref.watch(assetCacheServiceProvider),
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
				
			|||||||
@ -21,15 +21,28 @@ class AssetNotifier extends StateNotifier<List<AssetResponseDto>> {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  getAllAsset() async {
 | 
					  getAllAsset() async {
 | 
				
			||||||
 | 
					    final stopwatch = Stopwatch();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (_assetCacheService.isValid() && state.isEmpty) {
 | 
					    if (_assetCacheService.isValid() && state.isEmpty) {
 | 
				
			||||||
 | 
					      stopwatch.start();
 | 
				
			||||||
      state = await _assetCacheService.getAssetsAsync();
 | 
					      state = await _assetCacheService.getAssetsAsync();
 | 
				
			||||||
 | 
					      debugPrint("Reading assets from cache: ${stopwatch.elapsedMilliseconds}ms");
 | 
				
			||||||
 | 
					      stopwatch.reset();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    stopwatch.start();
 | 
				
			||||||
    var allAssets = await _assetService.getAllAsset();
 | 
					    var allAssets = await _assetService.getAllAsset();
 | 
				
			||||||
 | 
					    debugPrint("Query assets from API: ${stopwatch.elapsedMilliseconds}ms");
 | 
				
			||||||
 | 
					    stopwatch.reset();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (allAssets != null) {
 | 
					    if (allAssets != null) {
 | 
				
			||||||
      state = allAssets;
 | 
					      state = allAssets;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      stopwatch.start();
 | 
				
			||||||
      _cacheState();
 | 
					      _cacheState();
 | 
				
			||||||
 | 
					      debugPrint("Store assets in cache: ${stopwatch.elapsedMilliseconds}ms");
 | 
				
			||||||
 | 
					      stopwatch.reset();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user