Fix: Set localID for all files with same uploadedFileID

This commit is contained in:
Neeraj Gupta 2022-09-02 13:12:46 +05:30
parent 81beff6f1d
commit 3baafc72fb
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
3 changed files with 27 additions and 6 deletions

View file

@ -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(

View file

@ -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,7 +517,7 @@ class FileUploader {
orElse: () => null,
);
if (sameLocalSameCollection != null) {
debugPrint(
_logger.fine(
"sameLocalSameCollection: \n toUpload ${fileToUpload.tag()} "
"\n existing: ${sameLocalSameCollection.tag()}",
);
@ -536,12 +535,16 @@ 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);
return Tuple2(true, fileMissingLocalButSameCollection);
}
@ -565,6 +568,14 @@ 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);
}

View file

@ -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';