From a1a574a72583556eba5c39f66f3f30fb8c2d8566 Mon Sep 17 00:00:00 2001 From: inventory69 Date: Wed, 11 Feb 2026 10:15:33 +0100 Subject: [PATCH] fix(sync): IMPL_08B - Bypass global cooldown for onSave syncs Changes: - Constants.kt: Add SYNC_ONSAVE_TAG constant for worker tagging - NoteEditorViewModel.triggerOnSaveSync(): Tag SyncWorker with "onsave" tag - SyncWorker.doWork(): Skip global cooldown check for onSave-tagged workers - onSave retains 3 protection layers: 5s own throttle, tryStartSync mutex, syncMutex - Auto/WiFi/periodic syncs still respect 30s global cooldown --- .../main/java/dev/dettmer/simplenotes/sync/SyncWorker.kt | 9 +++++++-- .../dettmer/simplenotes/ui/editor/NoteEditorViewModel.kt | 1 + .../main/java/dev/dettmer/simplenotes/utils/Constants.kt | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/dev/dettmer/simplenotes/sync/SyncWorker.kt b/android/app/src/main/java/dev/dettmer/simplenotes/sync/SyncWorker.kt index 6872f79..36ca5d2 100644 --- a/android/app/src/main/java/dev/dettmer/simplenotes/sync/SyncWorker.kt +++ b/android/app/src/main/java/dev/dettmer/simplenotes/sync/SyncWorker.kt @@ -111,8 +111,13 @@ class SyncWorker( // Verhindert dass Foreground und Background gleichzeitig syncing-State haben val prefs = applicationContext.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_PRIVATE) - // Globaler Cooldown-Check (verhindert unnötige Server-Checks) - if (!SyncStateManager.canSyncGlobally(prefs)) { + // 🆕 v1.8.1 (IMPL_08B): onSave-Syncs bypassen den globalen Cooldown + // Grund: User hat explizit gespeichert → erwartet zeitnahen Sync + // Der eigene 5s-Throttle + isSyncing-Mutex reichen als Schutz + val isOnSaveSync = tags.contains(Constants.SYNC_ONSAVE_TAG) + + // Globaler Cooldown-Check (nicht für onSave-Syncs) + if (!isOnSaveSync && !SyncStateManager.canSyncGlobally(prefs)) { Logger.d(TAG, "⏭️ SyncWorker: Global sync cooldown active - skipping") if (BuildConfig.DEBUG) { Logger.d(TAG, "✅ SyncWorker.doWork() SUCCESS (cooldown)") diff --git a/android/app/src/main/java/dev/dettmer/simplenotes/ui/editor/NoteEditorViewModel.kt b/android/app/src/main/java/dev/dettmer/simplenotes/ui/editor/NoteEditorViewModel.kt index 1e84236..7aac05d 100644 --- a/android/app/src/main/java/dev/dettmer/simplenotes/ui/editor/NoteEditorViewModel.kt +++ b/android/app/src/main/java/dev/dettmer/simplenotes/ui/editor/NoteEditorViewModel.kt @@ -545,6 +545,7 @@ class NoteEditorViewModel( Logger.d(TAG, "📤 Triggering onSave sync") val syncRequest = OneTimeWorkRequestBuilder() .addTag(Constants.SYNC_WORK_TAG) + .addTag(Constants.SYNC_ONSAVE_TAG) // 🆕 v1.8.1 (IMPL_08B): Bypassed globalen Cooldown .build() WorkManager.getInstance(getApplication()).enqueue(syncRequest) } diff --git a/android/app/src/main/java/dev/dettmer/simplenotes/utils/Constants.kt b/android/app/src/main/java/dev/dettmer/simplenotes/utils/Constants.kt index 5eacb39..da66aee 100644 --- a/android/app/src/main/java/dev/dettmer/simplenotes/utils/Constants.kt +++ b/android/app/src/main/java/dev/dettmer/simplenotes/utils/Constants.kt @@ -86,4 +86,7 @@ object Constants { // 🆕 v1.8.1 (IMPL_08): Globaler Sync-Cooldown (über alle Trigger hinweg) const val KEY_LAST_GLOBAL_SYNC_TIME = "last_global_sync_timestamp" const val MIN_GLOBAL_SYNC_INTERVAL_MS = 30_000L // 30 Sekunden + + // 🆕 v1.8.1 (IMPL_08B): onSave-Sync Worker-Tag (bypassed globalen Cooldown) + const val SYNC_ONSAVE_TAG = "onsave" }