Skip to content

fix share count changes#46

Merged
bretth18 merged 9 commits into
mainfrom
b/upload-completion
May 7, 2026
Merged

fix share count changes#46
bretth18 merged 9 commits into
mainfrom
b/upload-completion

Conversation

@bretth18

@bretth18 bretth18 commented May 7, 2026

Copy link
Copy Markdown
Owner

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:

  • Added a debounced, multi-subscriber countsChangesStream() to ShareManager using fanned-out AsyncStream continuations, with atomic notification after folder add/remove/scan and a 200ms debounce to coalesce rapid changes. [1] [2] [3] [4]
  • NetworkClient now consumes countsChangesStream() 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:

  • ShareManager now accepts an injectable UserDefaults store, improving testability and preventing test cross-talk, and all persistence/load methods now use this injected store. The loadPersistedFolders() method is split from scanning so notification subscribers can be registered before a rescan. [1] [2] [3]
  • Ensured security-scoped resource access is correctly reference-counted, avoiding leaks on redundant folder adds.

Async task and connection handling:

  • All async consumer tasks in NetworkClient now use weak self references per iteration to avoid retain cycles, ensuring tasks terminate cleanly when the client is deallocated. [1] [2]
  • In 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:

  • App startup now wires up share count change consumers before loading persisted folders and rescanning, guaranteeing that initial share statistics are broadcast and observed.

How to test

  • Ensure all checks pass

Author checklist

This PR:

  • Satisfies a goal that is specific & clearly motivated
  • Adds value in isolation (whether user-facing or sustainability-related)
  • Contains a concise & easy-to-understand title + description
  • Adheres to SRP by default
  • Presents the best possible implementation to meet its goal, given constraints at hand

@bretth18 bretth18 self-assigned this May 7, 2026
@bretth18 bretth18 merged commit 40b381d into main May 7, 2026
4 checks passed
@bretth18 bretth18 deleted the b/upload-completion branch May 7, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant