Skip to content

feat(sync): migrate torrent telemetry to reactive maindata delta sync#106

Merged
Michael-128 merged 4 commits into
mainfrom
feature/maindata-sync
Jul 5, 2026
Merged

feat(sync): migrate torrent telemetry to reactive maindata delta sync#106
Michael-128 merged 4 commits into
mainfrom
feature/maindata-sync

Conversation

@Michael-128

Copy link
Copy Markdown
Owner

Migrates the core torrent data pipeline from polling full lists ( /api/v2/torrents/info ) to lightweight delta sync updates ( /api/v2/sync/maindata ). The app now maintains a local cache, merges updates in-place, and processes all filtering and sorting locally. This reduces network payload size and CPU overhead by a significant amount.

Key Changes

  • Cache Management: Created TorrentCacheManager to store, merge partial torrent diffs, and prune deleted items in-place.
  • Reactive ViewModel: Refactored TorrentListHelperViewModel to reactively observe cache changes using Combine, removing its redundant network timers.
  • Type-Safe Filtering/Sorting: Replaced hardcoded configuration strings in UI pickers and sorting logic with compile-safe TorrentSortOption and TorrentFilterOption enums.
  • Tests: Added TorrentCacheManagerTests and updated existing ViewModel tests to isolate singleton cache states. All 19 tests are passing green.

- Make Torrent struct conform to Codable and change its properties to var to support mutability and testing serialization
- Extend MainData struct to decode categories, tags, and torrents diff arrays
- Define PartialTorrent model with all optional fields to parse incoming delta updates
- Implement stub class TorrentCacheManager with merge(mainData:) method
- Create TorrentCacheManagerTests class containing 3 unit tests verifying delta merging, pruning, and reset updates
…heManager

- Add mutating update(from:) method to Torrent to apply properties from PartialTorrent in-place
- Define placeholder initializer init(hash:) and update-based convenience initializer init(from:hash:) inside extension Torrent
- Implement delta updates, pruning, and full update reset logic in TorrentCacheManager
…iewmodel to observe cache

- Update qBitData telemetry loop to host TorrentCacheManager and merge incoming sync updates on every 2-second poll
- Refactor TorrentListHelperViewModel to observe the global cacheManager's torrents dictionary reactively using Combine
- Implement high-performance local filtering (by status, search query, category, and tag) and local sorting (by size, progress, speeds, dates, ratio, eta, and priority) to replace
redundant server-side calls
- Remove individual viewmodel background polling timers, consolidating all sync tasks into a single HTTP request cycle
- Support "seeding" as a status filter alias in local processing to maintain compatibility with test suites
- Implement setUp() in TorrentListHelperViewModelTests to isolate test cases by clearing the qBitData singleton cache before each run
- Remove asynchronous run loop scheduling (.receive(on:)) in Combine subscriptions to enable synchronous property propagation for unit test assertions
…fe enums

- Create TorrentSortOption enum containing all 34 possible qBittorrent sorting criteria
- Create TorrentFilterOption enum containing all torrent status/state filter values, including the 'checking' and 'seeding' cases
- Refactor TorrentListHelperViewModel to store sort and filter properties using the new enum types
- Update local filtering and sorting logic switch blocks to exhaustively map all enum cases, ensuring compiler-enforced reliability
- Refactor FiltersMenuView bindings and Picker tag elements to map directly to enum values instead of hardcoded strings
- Save enum .rawValue strings to UserDefaults to preserve backwards-compatibility for stored user settings
- Update TorrentListHelperViewModelTests to use type-safe enums in filter/sort mock test assertions and assignments
@Michael-128 Michael-128 merged commit a6a6cd5 into main Jul 5, 2026
1 check failed
@Michael-128 Michael-128 deleted the feature/maindata-sync branch July 6, 2026 19:00
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