Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Mini refactor

laurenspriemd25e81282de7
diff --git a/mobile/lib/services/smart_memories_service.dart b/mobile/lib/services/smart_memories_service.dart
index 2afe4190aa..2d5d5b4230 100644
--- a/mobile/lib/services/smart_memories_service.dart
+++ b/mobile/lib/services/smart_memories_service.dart
@@ -496,12 +496,13 @@ class SmartMemoriesService {
final List<(List<EnteFile>, Location)> smallRadiusClusters = [];
final List<(List<EnteFile>, Location)> wideRadiusClusters = [];
// Go through all files and cluster the ones not inside any location tag
+ allFilesLoop:
for (EnteFile file in allFiles) {
if (!file.hasLocation ||
file.uploadedFileID == null ||
!file.isOwner ||
file.creationTime == null) {
- continue;
+ continue allFilesLoop;
}
// Check if the file is inside any location tag
bool hasLocationTag = false;
@@ -516,42 +517,41 @@ class SmartMemoriesService {
}
}
// Cluster the files not inside any location tag (incremental clustering)
- if (!hasLocationTag) {
- // Small radius clustering for base locations
- bool foundSmallCluster = false;
- for (final cluster in smallRadiusClusters) {
- final clusterLocation = cluster.$2;
- if (isFileInsideLocationTag(
- clusterLocation,
- file.location!,
- 0.6,
- )) {
- cluster.$1.add(file);
- foundSmallCluster = true;
- break;
- }
- }
- if (!foundSmallCluster) {
- smallRadiusClusters.add(([file], file.location!));
- }
- // Wide radius clustering for trip locations
- bool foundWideCluster = false;
- for (final cluster in wideRadiusClusters) {
- final clusterLocation = cluster.$2;
- if (isFileInsideLocationTag(
- clusterLocation,
- file.location!,
- 100.0,
- )) {
- cluster.$1.add(file);
- foundWideCluster = true;
- break;
- }
+ if (hasLocationTag) continue allFilesLoop;
+ // Small radius clustering for base locations
+ bool addedToExistingSmallCluster = false;
+ for (final cluster in smallRadiusClusters) {
+ final clusterLocation = cluster.$2;
+ if (isFileInsideLocationTag(
+ clusterLocation,
+ file.location!,
+ 0.6,
+ )) {
+ cluster.$1.add(file);
+ addedToExistingSmallCluster = true;
+ break;
}
- if (!foundWideCluster) {
- wideRadiusClusters.add(([file], file.location!));
+ }
+ if (!addedToExistingSmallCluster) {
+ smallRadiusClusters.add(([file], file.location!));
+ }
+ // Wide radius clustering for trip locations
+ bool addedToExistingWideCluster = false;
+ for (final cluster in wideRadiusClusters) {
+ final clusterLocation = cluster.$2;
+ if (isFileInsideLocationTag(
+ clusterLocation,
+ file.location!,
+ 100.0,
+ )) {
+ cluster.$1.add(file);
+ addedToExistingWideCluster = true;
+ break;
}
}
+ if (!addedToExistingWideCluster) {
+ wideRadiusClusters.add(([file], file.location!));
+ }
}
// Identify base locations
@@ -577,11 +577,11 @@ class SmartMemoriesService {
final lastCreationTime = DateTime.fromMicrosecondsSinceEpoch(
creationTimes.last,
);
- if (lastCreationTime.difference(firstCreationTime).inDays < 90) {
+ final daysRange = lastCreationTime.difference(firstCreationTime).inDays;
+ if (daysRange < 90) {
continue;
}
// Check for a minimum average number of days photos are clicked in range
- final daysRange = lastCreationTime.difference(firstCreationTime).inDays;
if (uniqueDays.length < daysRange * 0.1) continue;
// Check if it's a current or old base location
final bool isCurrent = lastCreationTime.isAfter(
@@ -1354,9 +1354,9 @@ class SmartMemoriesService {
final fileToScore = await MLComputer.instance
.compareEmbeddings(vectors, _clipPositiveTextVector!);
final fileIdToClip = <int, EmbeddingVector>{};
- for (final vector in vectors) {
- fileIdToClip[vector.fileID] = vector;
- }
+ for (final vector in vectors) {
+ fileIdToClip[vector.fileID] = vector;
+ }
// Get face scores for each file
final fileToFaceCount = <int, int>{};