perf: optimize video stream processing state management
- Move isCurrentlyProcessing to widget state for better performance - Only call setState when processing state actually changes - Add comprehensive processing status handling (retry, compressing, uploading) - Remove redundant service calls from build method - Clean up unnecessary early returns and duplicate logic 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user