chore: update addFiles logic

This commit is contained in:
Prateek Sunal
2025-07-29 13:00:37 +05:30
parent 79fdfdd72b
commit 03d21bc3ff
2 changed files with 29 additions and 19 deletions

View File

@@ -43,16 +43,25 @@ class SmartAlbumConfig {
);
}
SmartAlbumConfig addFiles(String personId, int updatedAt, Set<int> fileId) {
if (!infoMap.containsKey(personId)) {
return this;
}
SmartAlbumConfig addFiles(
Map<String, int> personUpdatedAt,
Map<String, Set<int>> personMappedFiles,
) {
final newInfoMap = Map<String, PersonInfo>.from(infoMap);
newInfoMap[personId] = (
updatedAt: updatedAt,
addedFiles: newInfoMap[personId]!.addedFiles.union(fileId),
);
var isUpdated = false;
personMappedFiles.forEach((personId, fileIds) {
if (newInfoMap.containsKey(personId)) {
isUpdated = true;
newInfoMap[personId] = (
updatedAt: personUpdatedAt[personId] ??
DateTime.now().millisecondsSinceEpoch,
addedFiles: {...?newInfoMap[personId]?.addedFiles, ...fileIds},
);
}
});
if (!isUpdated) return this;
return SmartAlbumConfig(
id: id,

View File

@@ -113,7 +113,7 @@ class SmartAlbumsService {
config.personIDs.toList(),
);
Set<EnteFile> toBeSynced = {};
Map<String, List<EnteFile>> toBeSynced = {};
var newConfig = config;
for (final personId in config.personIDs) {
@@ -137,13 +137,7 @@ class SmartAlbumsService {
e.ownerID != userId,
);
toBeSynced = {...toBeSynced, ...fileIds};
newConfig = newConfig.addFiles(
personId,
updatedAtMap[personId]!,
toBeSynced.map((e) => e.uploadedFileID!).toSet(),
);
toBeSynced = {...toBeSynced, personId: fileIds};
}
syncingCollection = (collectionId, true);
@@ -154,9 +148,16 @@ class SmartAlbumsService {
if (toBeSynced.isNotEmpty) {
try {
await CollectionsService.instance.addOrCopyToCollection(
toCopy: false,
collectionId,
toBeSynced.toList(),
toBeSynced.entries.map((e) => e.value).expand((e) => e).toList(),
toCopy: false,
);
newConfig = newConfig.addFiles(
updatedAtMap,
toBeSynced.map(
(key, value) =>
MapEntry(key, value.map((e) => e.uploadedFileID!).toSet()),
),
);
await saveConfig(newConfig);