perf: eliminate full rescans with local caches; add queue tracking, notifications, SyncView redesign

Cached indexes:
- NASManifestCache: actor-based disk cache for the NAS manifest (kisani_manifest_cache.json)
  Avoids NAS network round-trip when cache < 5 min old. Updated after every manifest download.
- LocalPhotoIndex: actor-based disk cache of phone asset metadata (kisani_local_index.json)
  Built once on first launch, then updated incrementally via PHPhotoLibraryChangeObserver.
  O(1) countSafe via in-memory dict (vs PHFetchResult batch enumeration + CoreData calls).

Fast path reconcile:
  When both caches are warm, reconcile() skips NAS connection + PHFetchResult enumeration
  entirely and returns in microseconds. Falls through to full NAS path only when stale.

AutoBackupCoordinator.onActive():
  Changed force: true → force: false so the 30-second debounce prevents expensive rescans
  on rapid app foreground/background cycles. Dashboard appears instantly from cached snapshot.

BackupQueueItem + queue tracking:
  BackupEngine publishes queueItems: [BackupQueueItem] with per-file status, progress,
  speed, error details. Queue is persisted to disk and reloaded on next launch so SyncView
  always has data to show even after restart.

NotificationService:
  Centralised local notification sender replacing the inline UNMutableNotificationContent
  blocks. Sends for: backup started, completed, failed, paused, NAS offline. Uses category
  identifiers so same-type notifications replace each other.

SyncView redesign:
  - Removed pill/chip around NAS IP — replaced with plain "Online/Offline/Checking" dot+text
  - No live NAS directory listing (was expensive NAS connection on every tab open)
  - Shows engine.queueItems grouped into Active / Failed / Completed sections
  - Per-file rows with inline progress bar + bytes/speed for uploading items, error text for failed
  - Idle state shows archive count from statusService snapshot

GalleryViewModel:
  NAS tab and All tab now use NASManifestCache as fallback when statusService.lastManifest
  is nil (offline launch). Gallery shows NAS items even when NAS is unreachable.

AppDelegate:
  Bootstraps LocalPhotoIndex.loadOrBuild() in background on launch (non-blocking).

Co-Authored-By: Kutesir <kutesir@provoc.ug>
Co-Authored-By: Sentry <sentry@provoc.ug>
This commit is contained in:
Robin Kutesa
2026-05-17 23:28:29 +03:00
parent 025326f2b2
commit 1afcbaff96
11 changed files with 786 additions and 325 deletions

View File

@@ -21,6 +21,7 @@
19CB72B2DCA08EC8C8EB3103 /* UGreenCompatibilityBadge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 63B4A0DF226AB4C5EE9E0D16 /* UGreenCompatibilityBadge.swift */; };
1AEF3190A6F5D3AB43CC521D /* BackupEngineTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35A5F6ABBD052F931949B2FA /* BackupEngineTests.swift */; };
20F9E76FDA60BA806980E44A /* ToggleRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 674029116718AB4525AD9450 /* ToggleRow.swift */; };
210BF39897CC8E966A72698C /* BackupQueueItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF4EDDA4B02ABF0F17BE86D5 /* BackupQueueItem.swift */; };
218313D06E536CC541620B1A /* GalleryDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18ADB8B4D428026420CCA46B /* GalleryDetailView.swift */; };
24B0F2FC039AF5898BF3ADAE /* Date+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57448AD7D80B10985B8A222B /* Date+.swift */; };
280D31F6A61529FB13A06EA4 /* SMBClient in Frameworks */ = {isa = PBXBuildFile; productRef = BD0A57EC048DFE706E440152 /* SMBClient */; };
@@ -50,6 +51,7 @@
8CA733E7E328A54503A06728 /* ConnectionStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 101678CDEDFF343DCC880C2F /* ConnectionStore.swift */; };
957976696AD0F01A7BA054DE /* BackgroundTaskManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AC6E57C1203C70B43C3A789 /* BackgroundTaskManager.swift */; };
97E28F8EF7418C7D7A4797B1 /* AppTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = E309F9924060F6C3C2FE36D4 /* AppTheme.swift */; };
9B1A3CDC25CC5F058086A08E /* NASManifestCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = E317DD286568B85367A66AD3 /* NASManifestCache.swift */; };
A12ED84B089F39AF5A26F246 /* PhotoLibraryService.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDB76E9F93340DD33C5572DB /* PhotoLibraryService.swift */; };
A30DD79EAA22C33F029FE4E4 /* LANTriggerSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D7C31A6C73BBF5B8CBDCF2 /* LANTriggerSection.swift */; };
A43FF80A5C7FC09E07294B60 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 628B4A8E8DDB28CDF5AE4284 /* AppDelegate.swift */; };
@@ -60,8 +62,10 @@
C172F81135C5C7EDBED90E98 /* MainTabView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3306187119851CE3E989408 /* MainTabView.swift */; };
D18F0F1DCFEB945F2AD6DC20 /* ConnectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C29AB7B029DBC37E189C81D6 /* ConnectView.swift */; };
D2EB2844309ECB331955F2A9 /* SFTPService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF029B56DE72F2D5D7977D95 /* SFTPService.swift */; };
D3CEB99B305997997AFEE0D9 /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2145CC30FC82AE2E0703EBCE /* NotificationService.swift */; };
D7C3444EF261573E590725E9 /* MockNASService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B1138B91494A6B3BF4515C0 /* MockNASService.swift */; };
D8247C4721601698EB006C86 /* GalleryItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEE62B5210F46415531D531D /* GalleryItem.swift */; };
D917AA4FEDD50459938E7CD3 /* LocalPhotoIndex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E0B91084FBA758D1963CB1E /* LocalPhotoIndex.swift */; };
E6E8A98506D79BB36771FA16 /* GalleryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB509370FEEE38EA8732FDE /* GalleryView.swift */; };
EAD70575AAC91030698676E1 /* KisaniLogoMark.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0987D44494F1385E8D4876F /* KisaniLogoMark.swift */; };
EE8AE9228AC7BA87E0985BDF /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = A1DAA26CE0A4DFFDD90370F2 /* PrivacyInfo.xcprivacy */; };
@@ -87,6 +91,7 @@
18ADB8B4D428026420CCA46B /* GalleryDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryDetailView.swift; sourceTree = "<group>"; };
1AB509370FEEE38EA8732FDE /* GalleryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryView.swift; sourceTree = "<group>"; };
1AF29317285580DD2246F54F /* ThumbnailCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThumbnailCache.swift; sourceTree = "<group>"; };
2145CC30FC82AE2E0703EBCE /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
22BF6D1FB493F75096805690 /* FolderSetupView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderSetupView.swift; sourceTree = "<group>"; };
248BF8DA762BB74955255511 /* ConnectViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectViewModelTests.swift; sourceTree = "<group>"; };
2B1138B91494A6B3BF4515C0 /* MockNASService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockNASService.swift; sourceTree = "<group>"; };
@@ -103,6 +108,7 @@
4512EE2A2DE276DB46690E06 /* ButtonStyles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonStyles.swift; sourceTree = "<group>"; };
57448AD7D80B10985B8A222B /* Date+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+.swift"; sourceTree = "<group>"; };
5AA5C090CF766ED8E3AF77D1 /* KeychainStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainStore.swift; sourceTree = "<group>"; };
5E0B91084FBA758D1963CB1E /* LocalPhotoIndex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalPhotoIndex.swift; sourceTree = "<group>"; };
6004FE7B107CC60894EDC434 /* BrowseView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowseView.swift; sourceTree = "<group>"; };
628B4A8E8DDB28CDF5AE4284 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
63B4A0DF226AB4C5EE9E0D16 /* UGreenCompatibilityBadge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UGreenCompatibilityBadge.swift; sourceTree = "<group>"; };
@@ -130,10 +136,12 @@
DAF503BCE3AEDC25F4D35083 /* NASConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NASConnection.swift; sourceTree = "<group>"; };
DEFC3DC5AA3C7B7258C9155A /* BackupJob.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackupJob.swift; sourceTree = "<group>"; };
E309F9924060F6C3C2FE36D4 /* AppTheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppTheme.swift; sourceTree = "<group>"; };
E317DD286568B85367A66AD3 /* NASManifestCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NASManifestCache.swift; sourceTree = "<group>"; };
E956B8562EDB9259034CF8FF /* AppMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppMenuView.swift; sourceTree = "<group>"; };
E987653F4F7129568656EFDE /* BackupResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackupResult.swift; sourceTree = "<group>"; };
ED5F358675A200A5C0FF2289 /* NASBackup.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = NASBackup.app; sourceTree = BUILT_PRODUCTS_DIR; };
EF029B56DE72F2D5D7977D95 /* SFTPService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SFTPService.swift; sourceTree = "<group>"; };
EF4EDDA4B02ABF0F17BE86D5 /* BackupQueueItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackupQueueItem.swift; sourceTree = "<group>"; };
F052EE8B0A757532E4BCBCCD /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; };
F0987D44494F1385E8D4876F /* KisaniLogoMark.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KisaniLogoMark.swift; sourceTree = "<group>"; };
F13BE4A26BEF38CE3043CBB5 /* FolderRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderRow.swift; sourceTree = "<group>"; };
@@ -244,6 +252,7 @@
children = (
DEFC3DC5AA3C7B7258C9155A /* BackupJob.swift */,
966927456571CE45600BEF75 /* BackupManifest.swift */,
EF4EDDA4B02ABF0F17BE86D5 /* BackupQueueItem.swift */,
E987653F4F7129568656EFDE /* BackupResult.swift */,
2EDEAE39E0AFC06D0C169589 /* BackupStatusSnapshot.swift */,
CEE62B5210F46415531D531D /* GalleryItem.swift */,
@@ -260,6 +269,9 @@
75FEBDDA82656772FE30609D /* BackupEngine.swift */,
FC516E4CBDFA09B6D04937D6 /* BackupStatusService.swift */,
D008AD85FA9B690DAFECCC34 /* LANMonitor.swift */,
5E0B91084FBA758D1963CB1E /* LocalPhotoIndex.swift */,
E317DD286568B85367A66AD3 /* NASManifestCache.swift */,
2145CC30FC82AE2E0703EBCE /* NotificationService.swift */,
FDB76E9F93340DD33C5572DB /* PhotoLibraryService.swift */,
EF029B56DE72F2D5D7977D95 /* SFTPService.swift */,
3E4F11D9683F64A06B855649 /* SMBService.swift */,
@@ -509,6 +521,7 @@
67149DE0D19696D9327AEBAB /* BackupError.swift in Sources */,
42BF90A0F061C3183D5FD5D4 /* BackupJob.swift in Sources */,
0E446A91CD30C2905B8E215F /* BackupManifest.swift in Sources */,
210BF39897CC8E966A72698C /* BackupQueueItem.swift in Sources */,
48A1C445346B6E84BB4955D3 /* BackupResult.swift in Sources */,
3C588AE6212D742D71A67A4C /* BackupStatusService.swift in Sources */,
405026F5EC0DD0D4CC636F0F /* BackupStatusSnapshot.swift in Sources */,
@@ -531,12 +544,15 @@
EAD70575AAC91030698676E1 /* KisaniLogoMark.swift in Sources */,
42CB7416A94CFEBC290D0E49 /* LANMonitor.swift in Sources */,
A30DD79EAA22C33F029FE4E4 /* LANTriggerSection.swift in Sources */,
D917AA4FEDD50459938E7CD3 /* LocalPhotoIndex.swift in Sources */,
0E4948C8E3326DF859341942 /* LoginView.swift in Sources */,
F5ED0D561D6F61180B4672FA /* LoginViewModel.swift in Sources */,
C172F81135C5C7EDBED90E98 /* MainTabView.swift in Sources */,
6A0D1B9133CBA5CBE403AB6A /* NASBackupApp.swift in Sources */,
01610BD782FA7F00787E8CB5 /* NASConnection.swift in Sources */,
9B1A3CDC25CC5F058086A08E /* NASManifestCache.swift in Sources */,
6D7C0DABECF5694E95B1F2F9 /* NASTransferProtocol.swift in Sources */,
D3CEB99B305997997AFEE0D9 /* NotificationService.swift in Sources */,
1157E530A5E3EC4563D20C32 /* PHAsset+.swift in Sources */,
0555485F0FD9D1D724B98B0D /* PhotoLibraryProtocol.swift in Sources */,
A12ED84B089F39AF5A26F246 /* PhotoLibraryService.swift in Sources */,