Skip to content

[mob][photos] Caching fix #5531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions mobile/lib/services/magic_cache_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,22 @@ class MagicCacheService {
_logger.info("No magic cache found");
return [];
}
final jsonString = file.readAsStringSync();
return MagicCache.decodeJsonToList(jsonString);
try {
final bytes = await file.readAsBytes();
final jsonString = String.fromCharCodes(bytes);
return MagicCache.decodeJsonToList(jsonString);
} catch (e, s) {
_logger.severe("Error reading or decoding cache file", e, s);
await file.delete();
rethrow;
}
}

Future<void> clearMagicCache() async {
final file = File(await _getCachePath());
if (file.existsSync()) {
await file.delete();
}
if (file.existsSync()) {
await file.delete();
}
}

Future<List<GenericSearchResult>> getMagicGenericSearchResult(
Expand Down
20 changes: 15 additions & 5 deletions mobile/lib/services/memories_cache_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,25 @@ class MemoriesCacheService {
allFileIdsToFile[file.uploadedFileID!] = file;
}
}
final jsonString = file.readAsStringSync();
return MemoriesCache.decodeFromJsonString(jsonString, allFileIdsToFile);
try {
final bytes = await file.readAsBytes();
final jsonString = String.fromCharCodes(bytes);
final cache =
MemoriesCache.decodeFromJsonString(jsonString, allFileIdsToFile);
_logger.info("Reading memories cache result from disk done");
return cache;
} catch (e, s) {
_logger.severe("Error reading or decoding cache file", e, s);
await file.delete();
return null;
}
}

Future<void> clearMemoriesCache() async {
final file = File(await _getCachePath());
if (file.existsSync()) {
await file.delete();
}
if (file.existsSync()) {
await file.delete();
}
_cachedMemories = null;
}
}
8 changes: 0 additions & 8 deletions mobile/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -780,14 +780,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.1.1"
flutter_datetime_picker_bdaya:
dependency: "direct main"
description:
name: flutter_datetime_picker_bdaya
sha256: "6cb42a7d659cb9a10afa0a390b81677e15fd2f7e340e7eaffabf770e6b6709c0"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
flutter_displaymode:
dependency: "direct main"
description:
Expand Down