-
Notifications
You must be signed in to change notification settings - Fork 34
Fix UI unresponsiveness during downloads (Issue #54) #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit addresses the UI freezing issue that occurs when multiple downloads are running simultaneously. Changes: - Add UI update throttling (500ms) to prevent excessive re-renders - Add file manager refresh throttling (2s) for expensive operations - Implement log batching in YoutubeDownloadQueueService (flushes every 5s instead of writing to DB on every log line) - Replace fire-and-forget async event handlers in YtdlpService with proper Channel-based log processing - Fix un-awaited InvokeAsync calls in Blazor components - Add 20 unit tests for YoutubeDownloadQueueService including thread safety tests for concurrent log appends The key improvements reduce database writes during YouTube downloads from 100+/download to ~5-10/download, and limit UI renders to 2/second max instead of unbounded updates.
Summary of ChangesHello @thromel, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the application's UI responsiveness and backend performance, particularly when handling multiple concurrent YouTube downloads. It addresses several identified root causes of unresponsiveness, including excessive UI re-renders and frequent database writes, by introducing intelligent throttling mechanisms and a more efficient asynchronous log processing pipeline. The changes aim to provide a smoother user experience and reduce the load on the database during intensive operations. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This is an excellent pull request that addresses critical UI performance issues through well-thought-out changes like UI throttling, log batching, and safer async handling. The introduction of comprehensive unit tests is also a great addition. My review focuses on a couple of subtle but important concurrency issues in the new log batching mechanism to ensure its robustness and prevent data loss.
SaveHere/SaveHere.Tests/Services/YoutubeDownloadQueueServiceTests.cs
Outdated
Show resolved
Hide resolved
CI NoteThe failing test The error is: This is a known issue with All 20 new tests added in this PR pass successfully, and all other existing tests pass (127/128 passed, 1 pre-existing failure). |
- Add SemaphoreSlim to prevent race conditions when multiple threads trigger FlushLogsAsync simultaneously for the same itemId - Re-queue logs on DbUpdateConcurrencyException instead of silently discarding them, preventing potential data loss - Strengthen test assertion to verify batching behavior by checking that subsequent logs within the flush interval are not immediately persisted - Properly dispose of SemaphoreSlim in CleanupLogsForItem
The test was failing in CI because it accessed _factory.Services which triggers WebApplicationFactory to start the server, causing a FileNotFoundException for MvcTestingAppManifest.json. The test doesn't actually need the factory - it only tests the local TestHttpMessageHandler. Removed the unnecessary factory dependency to fix the CI failure.
The test was using 'invalid<>name.txt' which contains characters that are invalid on Windows but valid on Linux, causing the test to fail in CI. Changed to use 'invalid/name.txt' which contains a path separator that is invalid in filenames on all platforms.
Summary
This PR fixes the UI freezing/unresponsiveness issue reported in #54 where components become unresponsive while downloading, particularly with multiple YouTube downloads.
Root Causes Identified
StateHasChangedcalls on every progress update)InvokeAsynccalls causing update queue buildupChanges Made
UI Components (
DownloadFromDirectLink.razor,DownloadVideoAudio.razor):StateHasChangedcallsInvokeAsynccallsInvokeAsyncpatternsYoutubeDownloadQueueService:
ConcurrentQueue- logs are queued in memory and flushed to database every 5 seconds instead of on every log lineFlushLogsAsync()method for explicit flushing on download completionYtdlpService:
async voidevent handlers with properChannel<T>-based log processingPerformance Improvements
Tests Added
YoutubeDownloadQueueServiceTest Plan
Fixes #54