Merge pull request #457 from ente-io/match_bug_fix
Fix: Set localID for all files with same uploadedFileID
This commit is contained in:
commit
a3109c1dfa
3 changed files with 42 additions and 6 deletions
|
@ -894,6 +894,16 @@ class FilesDB {
|
|||
);
|
||||
}
|
||||
|
||||
Future<int> updateLocalIDForUploaded(int uploadedID, String localID) async {
|
||||
final db = await instance.database;
|
||||
return await db.update(
|
||||
table,
|
||||
{columnLocalID: localID},
|
||||
where: '$columnUploadedFileID = ? AND $columnLocalID IS NULL',
|
||||
whereArgs: [uploadedID],
|
||||
);
|
||||
}
|
||||
|
||||
Future<int> delete(int uploadedFileID) async {
|
||||
final db = await instance.database;
|
||||
return db.delete(
|
||||
|
|
|
@ -508,9 +508,8 @@ class FileUploader {
|
|||
if (existingUploadedFiles?.isEmpty ?? true) {
|
||||
// continueUploading this file
|
||||
return Tuple2(false, fileToUpload);
|
||||
} else {
|
||||
debugPrint("Found some matches");
|
||||
}
|
||||
|
||||
// case a
|
||||
final File sameLocalSameCollection = existingUploadedFiles.firstWhere(
|
||||
(e) =>
|
||||
|
@ -518,12 +517,19 @@ class FileUploader {
|
|||
orElse: () => null,
|
||||
);
|
||||
if (sameLocalSameCollection != null) {
|
||||
debugPrint(
|
||||
_logger.fine(
|
||||
"sameLocalSameCollection: \n toUpload ${fileToUpload.tag()} "
|
||||
"\n existing: ${sameLocalSameCollection.tag()}",
|
||||
);
|
||||
// should delete the fileToUploadEntry
|
||||
await FilesDB.instance.deleteByGeneratedID(fileToUpload.generatedID);
|
||||
|
||||
Bus.instance.fire(
|
||||
LocalPhotosUpdatedEvent(
|
||||
[fileToUpload],
|
||||
type: EventType.deletedFromEverywhere, //
|
||||
),
|
||||
);
|
||||
return Tuple2(true, sameLocalSameCollection);
|
||||
}
|
||||
|
||||
|
@ -536,13 +542,23 @@ class FileUploader {
|
|||
if (fileMissingLocalButSameCollection != null) {
|
||||
// update the local id of the existing file and delete the fileToUpload
|
||||
// entry
|
||||
debugPrint(
|
||||
_logger.fine(
|
||||
"fileMissingLocalButSameCollection: \n toUpload ${fileToUpload.tag()} "
|
||||
"\n existing: ${fileMissingLocalButSameCollection.tag()}",
|
||||
);
|
||||
fileMissingLocalButSameCollection.localID = fileToUpload.localID;
|
||||
await FilesDB.instance.insert(fileMissingLocalButSameCollection);
|
||||
// set localID for the given uploadedID across collections
|
||||
await FilesDB.instance.updateLocalIDForUploaded(
|
||||
fileMissingLocalButSameCollection.uploadedFileID,
|
||||
fileToUpload.localID,
|
||||
);
|
||||
await FilesDB.instance.deleteByGeneratedID(fileToUpload.generatedID);
|
||||
Bus.instance.fire(
|
||||
LocalPhotosUpdatedEvent(
|
||||
[fileToUpload],
|
||||
type: EventType.deletedFromEverywhere, //
|
||||
),
|
||||
);
|
||||
return Tuple2(true, fileMissingLocalButSameCollection);
|
||||
}
|
||||
|
||||
|
@ -565,6 +581,16 @@ class FileUploader {
|
|||
);
|
||||
return Tuple2(true, linkedFile);
|
||||
}
|
||||
final Set<String> matchLocalIDs = existingUploadedFiles
|
||||
.where(
|
||||
(e) => e.localID != null,
|
||||
)
|
||||
.map((e) => e.localID)
|
||||
.toSet();
|
||||
_logger.fine(
|
||||
"Found hashMatch but probably with diff localIDs "
|
||||
"$matchLocalIDs",
|
||||
);
|
||||
// case e
|
||||
return Tuple2(false, fileToUpload);
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(ente.File file) async {
|
|||
_logger.severe(errMsg);
|
||||
throw InvalidFileUploadState(errMsg);
|
||||
}
|
||||
String livePhotoVideoHash =
|
||||
final String livePhotoVideoHash =
|
||||
Sodium.bin2base64(await CryptoUtil.getHash(videoUrl));
|
||||
// imgHash:vidHash
|
||||
fileHash = '$fileHash$kLivePhotoHashSeparator$livePhotoVideoHash';
|
||||
|
|
Loading…
Add table
Reference in a new issue