Merge pull request #813 from ente-io/fix_redundant_fetch
Fix: Avoid redundant fetch for upload urls
This commit is contained in:
commit
bbef528135
2 changed files with 17 additions and 7 deletions
|
@ -477,6 +477,7 @@ class RemoteSyncService {
|
|||
final int toBeUploaded = filesToBeUploaded.length + updatedFileIDs.length;
|
||||
if (toBeUploaded > 0) {
|
||||
Bus.instance.fire(SyncStatusUpdate(SyncStatus.preparingForUpload));
|
||||
await _uploader.checkNetworkForUpload();
|
||||
// verify if files upload is allowed based on their subscription plan and
|
||||
// storage limit. To avoid creating new endpoint, we are using
|
||||
// fetchUploadUrls as alternative method.
|
||||
|
|
|
@ -271,18 +271,27 @@ class FileUploader {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> checkNetworkForUpload({bool isForceUpload = false}) async {
|
||||
// Note: We don't support force uploading currently. During force upload,
|
||||
// network check is skipped completely
|
||||
if (isForceUpload) {
|
||||
return;
|
||||
}
|
||||
final connectivityResult = await (Connectivity().checkConnectivity());
|
||||
final canUploadUnderCurrentNetworkConditions =
|
||||
(connectivityResult == ConnectivityResult.wifi ||
|
||||
Configuration.instance.shouldBackupOverMobileData());
|
||||
if (!canUploadUnderCurrentNetworkConditions) {
|
||||
throw WiFiUnavailableError();
|
||||
}
|
||||
}
|
||||
|
||||
Future<File> _tryToUpload(
|
||||
File file,
|
||||
int collectionID,
|
||||
bool forcedUpload,
|
||||
) async {
|
||||
final connectivityResult = await (Connectivity().checkConnectivity());
|
||||
final canUploadUnderCurrentNetworkConditions =
|
||||
(connectivityResult == ConnectivityResult.wifi ||
|
||||
Configuration.instance.shouldBackupOverMobileData());
|
||||
if (!canUploadUnderCurrentNetworkConditions && !forcedUpload) {
|
||||
throw WiFiUnavailableError();
|
||||
}
|
||||
await checkNetworkForUpload(isForceUpload: forcedUpload);
|
||||
final fileOnDisk = await FilesDB.instance.getFile(file.generatedID!);
|
||||
final wasAlreadyUploaded = fileOnDisk != null &&
|
||||
fileOnDisk.uploadedFileID != null &&
|
||||
|
|
Loading…
Add table
Reference in a new issue