[mob][photos] Fixes 'Not person' null response (#5747)

## Description

Fixes 'Not person' null response

## Tests

Tested in debug mode on my pixel phone.
This commit is contained in:
Laurens Priem 2025-04-28 20:41:37 +05:30 committed by GitHub
commit dda7b2a28e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 64 deletions

View File

@ -22,6 +22,7 @@ import "package:photos/services/search_service.dart";
import "package:photos/ui/home/memories/full_screen_memory.dart"; import "package:photos/ui/home/memories/full_screen_memory.dart";
import "package:photos/utils/navigation_util.dart"; import "package:photos/utils/navigation_util.dart";
import "package:shared_preferences/shared_preferences.dart"; import "package:shared_preferences/shared_preferences.dart";
import "package:synchronized/synchronized.dart";
class MemoriesCacheService { class MemoriesCacheService {
static const _lastMemoriesCacheUpdateTimeKey = "lastMemoriesCacheUpdateTime"; static const _lastMemoriesCacheUpdateTimeKey = "lastMemoriesCacheUpdateTime";
@ -39,7 +40,8 @@ class MemoriesCacheService {
List<SmartMemory>? _cachedMemories; List<SmartMemory>? _cachedMemories;
bool _shouldUpdate = false; bool _shouldUpdate = false;
bool _isUpdateInProgress = false;
final _memoriesUpdateLock = Lock();
MemoriesCacheService(this._prefs) { MemoriesCacheService(this._prefs) {
_logger.fine("MemoriesCacheService constructor"); _logger.fine("MemoriesCacheService constructor");
@ -160,24 +162,17 @@ class MemoriesCacheService {
return; return;
} }
_checkIfTimeToUpdateCache(); _checkIfTimeToUpdateCache();
return _memoriesUpdateLock.synchronized(() async {
if ((!_shouldUpdate && !forced)) {
_logger.info(
"No update needed (shouldUpdate: $_shouldUpdate, forced: $forced)",
);
}
_logger.info(
"Updating memories cache (shouldUpdate: $_shouldUpdate, forced: $forced)",
);
try { try {
if ((!_shouldUpdate && !forced) || _isUpdateInProgress) {
_logger.info(
"No update needed (shouldUpdate: $_shouldUpdate, forced: $forced, isUpdateInProgress $_isUpdateInProgress)",
);
if (_isUpdateInProgress) {
int waitingTime = 0;
while (_isUpdateInProgress && waitingTime < 60) {
await Future.delayed(const Duration(seconds: 1));
waitingTime++;
}
}
return;
}
_logger.info(
"Updating memories cache (shouldUpdate: $_shouldUpdate, forced: $forced, isUpdateInProgress $_isUpdateInProgress)",
);
_isUpdateInProgress = true;
final EnteWatch? w = final EnteWatch? w =
kDebugMode ? EnteWatch("MemoriesCacheService") : null; kDebugMode ? EnteWatch("MemoriesCacheService") : null;
w?.start(); w?.start();
@ -188,10 +183,10 @@ class MemoriesCacheService {
// calculate memories for this period and for the next period // calculate memories for this period and for the next period
final now = DateTime.now(); final now = DateTime.now();
final next = now.add(kMemoriesUpdateFrequency); final next = now.add(kMemoriesUpdateFrequency);
final nowResult = await smartMemoriesService.calcMemories(now, newCache); final nowResult =
await smartMemoriesService.calcMemories(now, newCache);
if (nowResult.isEmpty) { if (nowResult.isEmpty) {
_cachedMemories = []; _cachedMemories = [];
_isUpdateInProgress = false;
_logger.warning( _logger.warning(
"No memories found for now, not updating cache and returning early", "No memories found for now, not updating cache and returning early",
); );
@ -214,8 +209,9 @@ class MemoriesCacheService {
if (!file.existsSync()) { if (!file.existsSync()) {
file.createSync(recursive: true); file.createSync(recursive: true);
} }
_cachedMemories = _cachedMemories = nowResult.memories
nowResult.memories.where((memory) => memory.shouldShowNow()).toList(); .where((memory) => memory.shouldShowNow())
.toList();
locationService.baseLocations = nowResult.baseLocations; locationService.baseLocations = nowResult.baseLocations;
await file.writeAsBytes( await file.writeAsBytes(
MemoriesCache.encodeToJsonString(newCache).codeUnits, MemoriesCache.encodeToJsonString(newCache).codeUnits,
@ -225,9 +221,8 @@ class MemoriesCacheService {
w?.logAndReset('_cacheUpdated method done'); w?.logAndReset('_cacheUpdated method done');
} catch (e, s) { } catch (e, s) {
_logger.info("Error updating memories cache", e, s); _logger.info("Error updating memories cache", e, s);
} finally {
_isUpdateInProgress = false;
} }
});
} }
/// WARNING: Use for testing only, TODO: lau: remove later /// WARNING: Use for testing only, TODO: lau: remove later

View File

@ -176,7 +176,7 @@ class _FileSelectionActionsWidgetState
SelectionActionButton( SelectionActionButton(
icon: Icons.remove_circle_outline, icon: Icons.remove_circle_outline,
labelText: S.of(context).notPersonLabel(widget.person!.data.name), labelText: S.of(context).notPersonLabel(widget.person!.data.name),
onTap: anyUploadedFiles ? _onNotpersonClicked : null, onTap: _onNotpersonClicked,
), ),
); );
if (ownedFilesCount == 1) { if (ownedFilesCount == 1) {
@ -195,7 +195,7 @@ class _FileSelectionActionsWidgetState
SelectionActionButton( SelectionActionButton(
labelText: S.of(context).notThisPerson, labelText: S.of(context).notThisPerson,
icon: Icons.remove_circle_outline, icon: Icons.remove_circle_outline,
onTap: anyUploadedFiles ? _onRemoveFromClusterClicked : null, onTap: _onRemoveFromClusterClicked,
), ),
); );
} }