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;
|
final int toBeUploaded = filesToBeUploaded.length + updatedFileIDs.length;
|
||||||
if (toBeUploaded > 0) {
|
if (toBeUploaded > 0) {
|
||||||
Bus.instance.fire(SyncStatusUpdate(SyncStatus.preparingForUpload));
|
Bus.instance.fire(SyncStatusUpdate(SyncStatus.preparingForUpload));
|
||||||
|
await _uploader.checkNetworkForUpload();
|
||||||
// verify if files upload is allowed based on their subscription plan and
|
// verify if files upload is allowed based on their subscription plan and
|
||||||
// storage limit. To avoid creating new endpoint, we are using
|
// storage limit. To avoid creating new endpoint, we are using
|
||||||
// fetchUploadUrls as alternative method.
|
// 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(
|
Future<File> _tryToUpload(
|
||||||
File file,
|
File file,
|
||||||
int collectionID,
|
int collectionID,
|
||||||
bool forcedUpload,
|
bool forcedUpload,
|
||||||
) async {
|
) async {
|
||||||
final connectivityResult = await (Connectivity().checkConnectivity());
|
await checkNetworkForUpload(isForceUpload: forcedUpload);
|
||||||
final canUploadUnderCurrentNetworkConditions =
|
|
||||||
(connectivityResult == ConnectivityResult.wifi ||
|
|
||||||
Configuration.instance.shouldBackupOverMobileData());
|
|
||||||
if (!canUploadUnderCurrentNetworkConditions && !forcedUpload) {
|
|
||||||
throw WiFiUnavailableError();
|
|
||||||
}
|
|
||||||
final fileOnDisk = await FilesDB.instance.getFile(file.generatedID!);
|
final fileOnDisk = await FilesDB.instance.getFile(file.generatedID!);
|
||||||
final wasAlreadyUploaded = fileOnDisk != null &&
|
final wasAlreadyUploaded = fileOnDisk != null &&
|
||||||
fileOnDisk.uploadedFileID != null &&
|
fileOnDisk.uploadedFileID != null &&
|
||||||
|
|
Loading…
Add table
Reference in a new issue