Merge pull request #339 from ente-io/neeraj/mob-82-background-battery-drain

Minor improvements to reduce battery usage
This commit is contained in:
Vishnu Mohandas 2022-06-22 17:56:30 +05:30 committed by GitHub
commit fb7d71380e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 6 deletions

View file

@ -113,11 +113,11 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
stopOnTerminate: false,
startOnBoot: true,
enableHeadless: true,
requiresBatteryNotLow: false,
requiresBatteryNotLow: true,
requiresCharging: false,
requiresStorageNotLow: false,
requiresDeviceIdle: false,
requiredNetworkType: NetworkType.NONE,
requiredNetworkType: NetworkType.ANY,
), (String taskId) async {
await widget.runBackgroundTask(taskId);
}, (taskId) {

View file

@ -105,7 +105,6 @@ class RemoteSyncService {
_existingSync = null;
}
} catch (e, s) {
_logger.severe("Error executing remote sync ", e, s);
_existingSync.complete();
_existingSync = null;
// rethrow whitelisted error so that UI status can be updated correctly.
@ -114,7 +113,10 @@ class RemoteSyncService {
e is WiFiUnavailableError ||
e is StorageLimitExceededError ||
e is SyncStopRequestedError) {
_logger.warning("Error executing remote sync", e);
rethrow;
} else {
_logger.severe("Error executing remote sync ", e, s);
}
}
}
@ -268,6 +270,10 @@ class RemoteSyncService {
if (toBeUploaded > 0) {
Bus.instance.fire(SyncStatusUpdate(SyncStatus.preparing_for_upload));
// 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.
await _uploader.fetchUploadURLs(toBeUploaded);
}
final List<Future> futures = [];
for (final uploadedFileID in updatedFileIDs) {

View file

@ -650,20 +650,20 @@ class FileUploader {
Future<UploadURL> _getUploadURL() async {
if (_uploadURLs.isEmpty) {
await _fetchUploadURLs();
await fetchUploadURLs(_queue.length);
}
return _uploadURLs.removeFirst();
}
Future<void> _uploadURLFetchInProgress;
Future<void> _fetchUploadURLs() async {
Future<void> fetchUploadURLs(int fileCount) async {
_uploadURLFetchInProgress ??= Future<void>(() async {
try {
final response = await _dio.get(
Configuration.instance.getHttpEndpoint() + "/files/upload-urls",
queryParameters: {
"count": min(42, 2 * _queue.length), // m4gic number
"count": min(42, fileCount * 2), // m4gic number
},
options: Options(
headers: {"X-Auth-Token": Configuration.instance.getToken()},