diff --git a/mobile/apps/photos/lib/db/files_db.dart b/mobile/apps/photos/lib/db/files_db.dart index 89e1612cc5..eea4697b4e 100644 --- a/mobile/apps/photos/lib/db/files_db.dart +++ b/mobile/apps/photos/lib/db/files_db.dart @@ -1,5 +1,4 @@ import "dart:async"; -import "dart:convert" show jsonDecode; import "dart:io"; import "package:computer/computer.dart"; @@ -1699,7 +1698,7 @@ class FilesDB with SqlDbBase { SELECT * FROM $filesTable WHERE $columnFileType = ? AND $columnCreationTime > ? - AND $columnUploadedFileID != -1 + AND ($columnUploadedFileID IS NOT NULL AND $columnUploadedFileID != -1) AND $columnOwnerID = $userID AND $columnLocalID IS NOT NULL AND ($columnFileSize IS NOT NULL AND $columnFileSize <= 524288000) @@ -1783,65 +1782,6 @@ class FilesDB with SqlDbBase { return ids.length; } - Future> remoteVideosCount() async { - final db = await instance.sqliteAsyncDB; - final results = await db.getAll( - ''' - SELECT DISTINCT $columnUploadedFileID FROM $filesTable - WHERE $columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS NOT -1 - AND $columnFileType = ? - ''', - [getInt(FileType.video)], - ); - final ids = {}; - for (final result in results) { - ids.add(result[columnUploadedFileID] as int); - } - return ids; - } - - Future> skippedVideosCount() async { - // skipped because video size > 500 MB || duration > 60 - final db = await instance.sqliteAsyncDB; - final results = await db.getAll( - ''' - SELECT DISTINCT $columnUploadedFileID FROM $filesTable - WHERE $columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS NOT -1 - AND (($columnFileSize IS NOT NULL AND $columnFileSize > 524288000) - OR ($columnDuration IS NOT NULL AND $columnDuration > 60)) - AND $columnFileType = ? - ''', - [getInt(FileType.video)], - ); - - final ids = {}; - for (final result in results) { - ids.add(result[columnUploadedFileID] as int); - } - - // get video files <= 10 MB - final results2 = await db.getAll( - ''' - SELECT DISTINCT $columnUploadedFileID, $columnPubMMdEncodedJson FROM $filesTable - WHERE $columnUploadedFileID IS NOT NULL AND $columnUploadedFileID IS NOT -1 - AND ($columnFileSize IS NOT NULL AND $columnFileSize <= 10485760) - AND $columnFileType = ? - ''', - [getInt(FileType.video)], - ); - for (final result in results2) { - // decode pub magic metadata and check sv == 1 - final pubMagicEncodedJson = result[columnPubMMdEncodedJson]; - if (pubMagicEncodedJson == null) continue; - final pubMagicMetadata = jsonDecode(pubMagicEncodedJson); - if (pubMagicMetadata['sv'] == 1) { - ids.add(result[columnUploadedFileID] as int); - } - } - - return ids; - } - ///Returns "columnName1 = ?, columnName2 = ?, ..." String _generateUpdateAssignmentsWithPlaceholders({ required int? fileGenId, diff --git a/mobile/apps/photos/lib/services/video_preview_service.dart b/mobile/apps/photos/lib/services/video_preview_service.dart index 2e4af816bc..fd67c0b2ce 100644 --- a/mobile/apps/photos/lib/services/video_preview_service.dart +++ b/mobile/apps/photos/lib/services/video_preview_service.dart @@ -123,25 +123,42 @@ class VideoPreviewService { } } + Future> _getFiles() async { + return await FilesDB.instance.getAllFilesAfterDate( + fileType: FileType.video, + beginDate: DateTime.now().subtract(const Duration(days: 60)), + userID: Configuration.instance.getUserID()!, + ); + } + Future getStatus() async { try { - final filesDB = FilesDB.instance; - final totalRemoteVideos = await filesDB.remoteVideosCount(); - final processed = fileDataService.previewIds.keys.toSet(); - final skippedVideos = (await filesDB.skippedVideosCount()).difference( - processed, - ); + // TODO: Should we consider all days we could have processed or last 60 days + final files = await _getFiles(); + final Set totalProcessed = fileDataService.previewIds.keys.toSet(); + final Set total = {}; + final Set processed = {}; + int skipped = 0; - final netTotal = totalRemoteVideos.difference(skippedVideos); + for (final file in files) { + if (totalProcessed.contains(file.uploadedFileID)) { + processed.add(file.uploadedFileID!); + continue; + } + if (file.pubMagicMetadata?.sv == 1) { + skipped++; + continue; + } + total.add(file.uploadedFileID!); + } - final double netProcessedItems = netTotal.isEmpty - ? 0 - : (processed.length / netTotal.length).clamp(0, 1); + final double netProcessedItems = + total.isEmpty ? 0 : (processed.length / total.length).clamp(0, 1); final status = StreamingStatus( netProcessedItems, - processed.length, - skippedVideos.length, - totalRemoteVideos.length, + totalProcessed.length, + skipped, + files.length, ); _logger.info("$status"); return status; @@ -844,11 +861,7 @@ class VideoPreviewService { } } catch (_) {} - final files = await FilesDB.instance.getAllFilesAfterDate( - fileType: FileType.video, - beginDate: DateTime.now().subtract(const Duration(days: 2000)), - userID: Configuration.instance.getUserID()!, - ); + final files = await _getFiles(); final previewIds = fileDataService.previewIds; final allFiles = diff --git a/mobile/apps/photos/lib/ui/settings/streaming/video_streaming_settings_page.dart b/mobile/apps/photos/lib/ui/settings/streaming/video_streaming_settings_page.dart index 91b924e074..aa970f31cd 100644 --- a/mobile/apps/photos/lib/ui/settings/streaming/video_streaming_settings_page.dart +++ b/mobile/apps/photos/lib/ui/settings/streaming/video_streaming_settings_page.dart @@ -260,7 +260,6 @@ class VideoStreamingStatusWidgetState builder: (context, snapshot) { if (snapshot.hasData) { final double netProcessed = snapshot.data!.netProcessedItems; - final int total = snapshot.data!.total; return Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -270,11 +269,9 @@ class VideoStreamingStatusWidgetState title: AppLocalizations.of(context).processed, ), trailingWidget: Text( - total < 1 - ? 'NA' - : netProcessed == 0 - ? '0%' - : '${(netProcessed * 100.0).toStringAsFixed(2)}%', + netProcessed == 0 + ? '0%' + : '${(netProcessed * 100.0).toStringAsFixed(2)}%', style: Theme.of(context).textTheme.bodySmall, ), singleBorderRadius: 8,