[mob][photos] Fallback if ML is off
This commit is contained in:
@@ -82,9 +82,13 @@ class MemoriesCacheService {
|
||||
return _prefs.getBool(_showAnyMemoryKey) ?? true;
|
||||
}
|
||||
|
||||
bool get enableSmartMemories => flagService.showSmartMemories;
|
||||
bool get enableSmartMemories =>
|
||||
flagService.showSmartMemories && flagService.hasGrantedMLConsent;
|
||||
|
||||
Future<void> _checkIfTimeToUpdateCache() async {
|
||||
if (!enableSmartMemories) {
|
||||
return;
|
||||
}
|
||||
if (lastMemoriesCacheUpdateTime <
|
||||
DateTime.now()
|
||||
.subtract(kMemoriesUpdateFrequency)
|
||||
@@ -121,6 +125,7 @@ class MemoriesCacheService {
|
||||
if (!showAnyMemories || !enableSmartMemories) {
|
||||
return;
|
||||
}
|
||||
await _checkIfTimeToUpdateCache();
|
||||
try {
|
||||
if ((!_shouldUpdate && !forced) || _isUpdateInProgress) {
|
||||
_logger.info(
|
||||
@@ -276,10 +281,10 @@ class MemoriesCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<SmartMemory>> _getMemoriesFromCache() async {
|
||||
Future<List<SmartMemory>?> _getMemoriesFromCache() async {
|
||||
final cache = await _readCacheFromDisk();
|
||||
if (cache == null) {
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
final result = await _fromCacheToMemories(cache);
|
||||
return result;
|
||||
@@ -289,10 +294,22 @@ class MemoriesCacheService {
|
||||
if (!showAnyMemories) {
|
||||
return [];
|
||||
}
|
||||
if (!enableSmartMemories) {
|
||||
final fillerMemories = await smartMemoriesService.calcFillerResults();
|
||||
return fillerMemories;
|
||||
}
|
||||
if (_cachedMemories != null) {
|
||||
return _cachedMemories!;
|
||||
}
|
||||
_cachedMemories = await _getMemoriesFromCache();
|
||||
if (_cachedMemories == null) {
|
||||
await updateCache(forced: true);
|
||||
_cachedMemories = await _getMemoriesFromCache();
|
||||
}
|
||||
if (_cachedMemories!.isEmpty) {
|
||||
_logger.severe("No memories found in (computed) cache, getting fillers");
|
||||
_cachedMemories = await smartMemoriesService.calcFillerResults();
|
||||
}
|
||||
return _cachedMemories!;
|
||||
}
|
||||
|
||||
|
||||
@@ -135,6 +135,15 @@ class SmartMemoriesService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<FillerMemory>> calcFillerResults() async {
|
||||
final now = DateTime.now();
|
||||
final allFiles = Set<EnteFile>.from(
|
||||
await SearchService.instance.getAllFilesForSearch(),
|
||||
);
|
||||
final fillerMemories = await _getFillerResults(allFiles, now);
|
||||
return fillerMemories;
|
||||
}
|
||||
|
||||
void _deductUsedMemories(
|
||||
Set<EnteFile> files,
|
||||
List<SmartMemory> memories,
|
||||
|
||||
@@ -54,7 +54,7 @@ class _MemoriesWidgetState extends State<MemoriesWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!MemoriesService.instance.showMemories) {
|
||||
if (!memoriesCacheService.showAnyMemories) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
if (memoriesCacheService.enableSmartMemories) {
|
||||
@@ -69,9 +69,6 @@ class _MemoriesWidgetState extends State<MemoriesWidget> {
|
||||
null,
|
||||
),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData && snapshot.data!.isEmpty) {
|
||||
return _oldMemories();
|
||||
}
|
||||
if (snapshot.hasError || !snapshot.hasData) {
|
||||
return SizedBox(
|
||||
height: _maxHeight + 12 + 10,
|
||||
|
||||
Reference in New Issue
Block a user