瀏覽代碼

Merge pull request #324 from ente-io/one_video_at_a_time

Vishnu Mohandas 3 年之前
父節點
當前提交
4e5cadcda6
共有 3 個文件被更改,包括 35 次插入11 次删除
  1. 1 1
      lib/ui/shared_collections_gallery.dart
  2. 33 9
      lib/utils/file_uploader.dart
  3. 1 1
      pubspec.yaml

+ 1 - 1
lib/ui/shared_collections_gallery.dart

@@ -251,7 +251,7 @@ class _SharedCollectionGalleryState extends State<SharedCollectionGallery>
               onTap: () async {
               onTap: () async {
                 await showToast(
                 await showToast(
                   context,
                   context,
-                  "Select an album and tap the share button on the top right to share.",
+                  "Open an album and tap the share button on the top right to share.",
                   toastLength: Toast.LENGTH_LONG,
                   toastLength: Toast.LENGTH_LONG,
                 );
                 );
                 Bus.instance.fire(
                 Bus.instance.fire(

+ 33 - 9
lib/utils/file_uploader.dart

@@ -22,6 +22,7 @@ import 'package:photos/events/subscription_purchased_event.dart';
 import 'package:photos/main.dart';
 import 'package:photos/main.dart';
 import 'package:photos/models/encryption_result.dart';
 import 'package:photos/models/encryption_result.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file.dart';
+import 'package:photos/models/file_type.dart';
 import 'package:photos/models/upload_url.dart';
 import 'package:photos/models/upload_url.dart';
 import 'package:photos/services/collections_service.dart';
 import 'package:photos/services/collections_service.dart';
 import 'package:photos/services/local_sync_service.dart';
 import 'package:photos/services/local_sync_service.dart';
@@ -33,6 +34,7 @@ import 'package:shared_preferences/shared_preferences.dart';
 
 
 class FileUploader {
 class FileUploader {
   static const kMaximumConcurrentUploads = 4;
   static const kMaximumConcurrentUploads = 4;
+  static const kMaximumConcurrentVideoUploads = 2;
   static const kMaximumThumbnailCompressionAttempts = 2;
   static const kMaximumThumbnailCompressionAttempts = 2;
   static const kMaximumUploadAttempts = 4;
   static const kMaximumUploadAttempts = 4;
   static const kBlockedUploadsPollFrequency = Duration(seconds: 2);
   static const kBlockedUploadsPollFrequency = Duration(seconds: 2);
@@ -49,7 +51,9 @@ class FileUploader {
   // Maintains the count of files in the current upload session.
   // Maintains the count of files in the current upload session.
   // Upload session is the period between the first entry into the _queue and last entry out of the _queue
   // Upload session is the period between the first entry into the _queue and last entry out of the _queue
   int _totalCountInUploadSession = 0;
   int _totalCountInUploadSession = 0;
-  int _currentlyUploading = 0;
+  // _uploadCounter indicates number of uploads which are currently in progress
+  int _uploadCounter = 0;
+  int _videoUploadCounter = 0;
   ProcessType _processType;
   ProcessType _processType;
   bool _isBackground;
   bool _isBackground;
   SharedPreferences _prefs;
   SharedPreferences _prefs;
@@ -228,18 +232,32 @@ class FileUploader {
       _totalCountInUploadSession = 0;
       _totalCountInUploadSession = 0;
       return;
       return;
     }
     }
-    if (_currentlyUploading < kMaximumConcurrentUploads) {
-      final firstPendingEntry = _queue.entries
+    if (_uploadCounter < kMaximumConcurrentUploads) {
+      var pendingEntry = _queue.entries
           .firstWhere(
           .firstWhere(
             (entry) => entry.value.status == UploadStatus.not_started,
             (entry) => entry.value.status == UploadStatus.not_started,
             orElse: () => null,
             orElse: () => null,
           )
           )
           ?.value;
           ?.value;
-      if (firstPendingEntry != null) {
-        firstPendingEntry.status = UploadStatus.in_progress;
+
+      if (pendingEntry != null &&
+          pendingEntry.file.fileType == FileType.video &&
+          _videoUploadCounter >= kMaximumConcurrentVideoUploads) {
+        // check if there's any non-video entry which can be queued for upload
+        pendingEntry = _queue.entries
+            .firstWhere(
+              (entry) =>
+                  entry.value.status == UploadStatus.not_started &&
+                  entry.value.file.fileType != FileType.video,
+              orElse: () => null,
+            )
+            ?.value;
+      }
+      if (pendingEntry != null) {
+        pendingEntry.status = UploadStatus.in_progress;
         _encryptAndUploadFileToCollection(
         _encryptAndUploadFileToCollection(
-          firstPendingEntry.file,
-          firstPendingEntry.collectionID,
+          pendingEntry.file,
+          pendingEntry.collectionID,
         );
         );
       }
       }
     }
     }
@@ -250,7 +268,10 @@ class FileUploader {
     int collectionID, {
     int collectionID, {
     bool forcedUpload = false,
     bool forcedUpload = false,
   }) async {
   }) async {
-    _currentlyUploading++;
+    _uploadCounter++;
+    if (file.fileType == FileType.video) {
+      _videoUploadCounter++;
+    }
     final localID = file.localID;
     final localID = file.localID;
     try {
     try {
       final uploadedFile =
       final uploadedFile =
@@ -273,7 +294,10 @@ class FileUploader {
         return null;
         return null;
       }
       }
     } finally {
     } finally {
-      _currentlyUploading--;
+      _uploadCounter--;
+      if (file.fileType == FileType.video) {
+        _videoUploadCounter--;
+      }
       _pollQueue();
       _pollQueue();
     }
     }
   }
   }

+ 1 - 1
pubspec.yaml

@@ -11,7 +11,7 @@ description: ente photos application
 # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
 # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
 # Read more about iOS versioning at
 # Read more about iOS versioning at
 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
-version: 0.5.43+323
+version: 0.5.45+325
 
 
 environment:
 environment:
   sdk: ">=2.10.0 <3.0.0"
   sdk: ">=2.10.0 <3.0.0"