Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Small pre-warm of memory lane

laurenspriem112dbb7bed95
diff --git a/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dart b/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dart
index e527763191..11d81b00d7 100644
--- a/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dart
+++ b/mobile/apps/photos/lib/services/memory_lane/memory_lane_service.dart
@@ -706,6 +706,71 @@ class MemoryLaneService {
}
}
+ Future<void> prewarmTimelineFrames(
+ String personId, {
+ int frameCount = 6,
+ }) async {
+ if (!isFeatureEnabled) return;
+ try {
+ final timeline = await _cacheService.getTimeline(personId);
+ if (timeline == null || !timeline.isReady || timeline.entries.isEmpty) {
+ return;
+ }
+ final entries = timeline.entries.take(frameCount).toList();
+ if (entries.isEmpty) {
+ return;
+ }
+ final uniqueFileIds =
+ entries.map((entry) => entry.fileId).toSet().toList();
+ final filesById = await _filesDB.getFileIDToFileFromIDs(uniqueFileIds);
+ final Map<int, Future<List<Face>?>> facesFutures = {};
+ final stopwatch = Stopwatch()..start();
+ int warmed = 0;
+ for (final entry in entries) {
+ final file = filesById[entry.fileId];
+ if (file == null) {
+ continue;
+ }
+ final facesFuture = facesFutures.putIfAbsent(
+ entry.fileId,
+ () => _mlDataDB.getFacesForGivenFileID(entry.fileId),
+ );
+ final faces = await facesFuture;
+ final face = faces?.firstWhereOrNull(
+ (element) => element.faceID == entry.faceId,
+ );
+ if (face == null) {
+ continue;
+ }
+ try {
+ await getCachedFaceCrops(
+ file,
+ [face],
+ useFullFile: true,
+ useTempCache: false,
+ );
+ warmed += 1;
+ } catch (error, stackTrace) {
+ _logger.fine(
+ "Memory Lane prewarm failed for $personId file ${entry.fileId}",
+ error,
+ stackTrace,
+ );
+ }
+ }
+ _logger.fine(
+ "Memory Lane prewarm person=$personId warmed=$warmed "
+ "target=$frameCount elapsed=${stopwatch.elapsedMilliseconds}ms",
+ );
+ } catch (error, stackTrace) {
+ _logger.fine(
+ "Memory Lane prewarm error for $personId",
+ error,
+ stackTrace,
+ );
+ }
+ }
+
Future<void> _refreshReadyPersonIds() async {
final cache = await _cacheService.getCache();
final current = cache.allTimelines
diff --git a/mobile/apps/photos/lib/ui/viewer/people/people_page.dart b/mobile/apps/photos/lib/ui/viewer/people/people_page.dart
index a5c34a2821..7f417f182c 100644
--- a/mobile/apps/photos/lib/ui/viewer/people/people_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/people/people_page.dart
@@ -69,6 +69,7 @@ class _PeoplePageState extends State<PeoplePage> {
late SearchFilterDataProvider? _searchFilterDataProvider;
ValueNotifier<Set<String>>? _timelineNotifier;
VoidCallback? _timelineListener;
+ bool _memoryLanePrewarmStarted = false;
bool get _memoryLaneEnabled => flagService.facesTimeline;
@@ -114,6 +115,7 @@ class _PeoplePageState extends State<PeoplePage> {
_timelineListener = () {
if (!mounted) return;
setState(() {});
+ _maybePrewarmMemoryLane();
};
_timelineNotifier!.addListener(_timelineListener!);
if (!MemoryLaneService.instance.hasReadyTimelineSync(
@@ -123,6 +125,8 @@ class _PeoplePageState extends State<PeoplePage> {
_person.remoteID,
trigger: "people_page_visit",
);
+ } else {
+ _maybePrewarmMemoryLane();
}
}
}
@@ -147,6 +151,24 @@ class _PeoplePageState extends State<PeoplePage> {
super.dispose();
}
+ void _maybePrewarmMemoryLane() {
+ if (_memoryLanePrewarmStarted || !_memoryLaneEnabled) {
+ return;
+ }
+ final bool memoryLaneReady =
+ MemoryLaneService.instance.hasReadyTimelineSync(_person.remoteID);
+ if (!memoryLaneReady) {
+ return;
+ }
+ _memoryLanePrewarmStarted = true;
+ unawaited(
+ MemoryLaneService.instance.prewarmTimelineFrames(
+ _person.remoteID,
+ frameCount: 6,
+ ),
+ );
+ }
+
Future<void> _openMemoryLanePage() async {
if (!_memoryLaneEnabled) return;
_timelineLogger.info("banner_tap person=${_person.remoteID}");