fix share count changes#46
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a robust, multi-subscriber notification system for share count changes, ensuring that share statistics are reliably broadcast to the server and UI after any folder or file index update. It also improves resource management, avoids retain cycles in async tasks, and makes share state persistence safer and more testable.
Share count change notifications and broadcasting:
countsChangesStream()toShareManagerusing fanned-outAsyncStreamcontinuations, with atomic notification after folder add/remove/scan and a 200ms debounce to coalesce rapid changes. [1] [2] [3] [4]NetworkClientnow consumescountsChangesStream()in a dedicated task, automatically re-broadcasting share counts to the server whenever the local share index changes—even while disconnected—eliminating race conditions where the server would report zero shared files after login. [1] [2] [3]Persistence and resource management improvements:
ShareManagernow accepts an injectableUserDefaultsstore, improving testability and preventing test cross-talk, and all persistence/load methods now use this injected store. TheloadPersistedFolders()method is split from scanning so notification subscribers can be registered before a rescan. [1] [2] [3]Async task and connection handling:
NetworkClientnow use weak self references per iteration to avoid retain cycles, ensuring tasks terminate cleanly when the client is deallocated. [1] [2]UploadManager, improved error handling for short reads and best-effort EOF signaling, surfacing partial transfers as failures and swallowing expected half-close errors when the peer disconnects first. [1] [2]App initialization changes:
How to test
Author checklist
This PR: