fix: update logic

This commit is contained in:
Prateek Sunal
2025-08-25 12:02:56 +05:30
parent 6db3741a3b
commit 13b2542bea
3 changed files with 35 additions and 85 deletions

View File

@@ -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<Set<int>> 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 = <int>{};
for (final result in results) {
ids.add(result[columnUploadedFileID] as int);
}
return ids;
}
Future<Set<int>> 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 = <int>{};
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,

View File

@@ -123,25 +123,42 @@ class VideoPreviewService {
}
}
Future<List<EnteFile>> _getFiles() async {
return await FilesDB.instance.getAllFilesAfterDate(
fileType: FileType.video,
beginDate: DateTime.now().subtract(const Duration(days: 60)),
userID: Configuration.instance.getUserID()!,
);
}
Future<StreamingStatus> 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<int> totalProcessed = fileDataService.previewIds.keys.toSet();
final Set<int> total = {};
final Set<int> 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 =

View File

@@ -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,