Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

perf: optimize video stream processing state management

Prateek Sunald38a09c3f0c7
diff --git a/mobile/apps/photos/lib/services/video_preview_service.dart b/mobile/apps/photos/lib/services/video_preview_service.dart
index 29d263cea5..5b90ce9483 100644
--- a/mobile/apps/photos/lib/services/video_preview_service.dart
+++ b/mobile/apps/photos/lib/services/video_preview_service.dart
@@ -157,8 +157,6 @@ class VideoPreviewService {
bool isCurrentlyProcessing(int? uploadedFileID) {
if (uploadedFileID == null) return false;
- // Check if file is actively being processed
- if (uploadingFileId == uploadedFileID) return true;
// Also check if file is in queue or other processing states
final item = _items[uploadedFileID];
diff --git a/mobile/apps/photos/lib/ui/viewer/file/video_stream_change.dart b/mobile/apps/photos/lib/ui/viewer/file/video_stream_change.dart
index ecca015a16..a99aaeede9 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/video_stream_change.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/video_stream_change.dart
@@ -32,27 +32,34 @@ class VideoStreamChangeWidget extends StatefulWidget {
class _VideoStreamChangeWidgetState extends State<VideoStreamChangeWidget> {
StreamSubscription<VideoPreviewStateChangedEvent>? _subscription;
+ bool isCurrentlyProcessing = false;
+
@override
void initState() {
super.initState();
+ // Initialize processing state safely in initState
+ isCurrentlyProcessing = VideoPreviewService.instance
+ .isCurrentlyProcessing(widget.file.uploadedFileID);
_subscription =
Bus.instance.on<VideoPreviewStateChangedEvent>().listen((event) {
final fileId = event.fileId;
- if (widget.file.uploadedFileID != fileId) {
- return; // Not for this file
- }
-
final status = event.status;
- // Handle different states
- switch (status) {
- case PreviewItemStatus.inQueue:
- case PreviewItemStatus.uploaded:
- case PreviewItemStatus.failed:
- setState(() {});
- break;
- default:
+ // Handle different states - will be false for different files or non-processing states
+ final newProcessingState = widget.file.uploadedFileID == fileId && switch (status) {
+ PreviewItemStatus.inQueue ||
+ PreviewItemStatus.retry ||
+ PreviewItemStatus.compressing ||
+ PreviewItemStatus.uploading =>
+ true,
+ _ => false,
+ };
+
+ // Only update state if value changed
+ if (isCurrentlyProcessing != newProcessingState) {
+ isCurrentlyProcessing = newProcessingState;
+ setState(() {});
}
});
}
@@ -80,13 +87,10 @@ class _VideoStreamChangeWidgetState extends State<VideoStreamChangeWidget> {
final bool isPreviewAvailable = widget.file.uploadedFileID != null &&
(fileDataService.previewIds.containsKey(widget.file.uploadedFileID));
- // Check if this file is currently being processed for streaming
- final bool isCurrentlyProcessing = VideoPreviewService.instance
- .isCurrentlyProcessing(widget.file.uploadedFileID);
-
// Get the current processing status for more specific messaging
- final processingStatus = widget.file.uploadedFileID != null
- ? VideoPreviewService.instance.getProcessingStatus(widget.file.uploadedFileID!)
+ final processingStatus = widget.file.uploadedFileID != null
+ ? VideoPreviewService.instance
+ .getProcessingStatus(widget.file.uploadedFileID!)
: null;
final colorScheme = getEnteColorScheme(context);