From 4b3a0692a91fdc3f985120b80f7dddd0fd873888 Mon Sep 17 00:00:00 2001 From: dab246 Date: Thu, 29 Jan 2026 10:35:25 +0700 Subject: [PATCH] TF-4274 Clear encryption keys with account cache. --- docs/adr/0070-sync-strategy-disappearing-emails.md | 9 ++++----- lib/features/caching/caching_manager.dart | 1 + .../login/data/local/encryption_key_cache_manager.dart | 5 +++++ .../controller/mailbox_dashboard_controller.dart | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/adr/0070-sync-strategy-disappearing-emails.md b/docs/adr/0070-sync-strategy-disappearing-emails.md index 7c314a24e..b670af69a 100644 --- a/docs/adr/0070-sync-strategy-disappearing-emails.md +++ b/docs/adr/0070-sync-strategy-disappearing-emails.md @@ -35,15 +35,15 @@ To resolve this, we are standardizing the **Cache Invalidation** triggers and in We define specific "Hard Actions" that must strictly trigger a complete cache clearance to ensure data freshness. We move away from "soft updates" for these specific interactions to guarantee the UI reflects the server state. * **F5 (Browser Refresh):** -* **Action:** Triggers `clear cache` Reloads application. +* **Action:** Triggers `clear cache` and reloads application. * **Logout:** -* **Action:** Triggers `clear cache` (Session wipe) Redirects to login. +* **Action:** Triggers `clear cache` (session wipe) and redirects to login. * **UI Refresh Button:** -* **Action:** Triggers `clear cache` explicitly for the current view Re-fetches list from server. +* **Action:** Triggers `clear cache` explicitly for the current view and re-fetches list from server. * *Rationale:* Previously, this might have only requested a delta update. Now it forces a clean slate fetch for the current list. @@ -75,8 +75,7 @@ FORCE_EMAIL_QUERY=false 1. **Reliability:** Directly addresses the "disappearing email" bug, ensuring users always see their actual messages. 2. **User Experience:** Eliminates the need for users to perform a disruptive Logout/Login cycle to restore their view. 3. **Maintainability:** By externalizing the logic to an environment variable (`FORCE_EMAIL_QUERY`), we allow DevOps/Developers to toggle query behaviors in different environments without altering source code. -4. **Clarity:** clearly defines what "Refresh" implies for the system (Clear Cache vs. Delta Update). - +4. **Clarity:** Clearly defines what "Refresh" implies for the system (Clear Cache vs. Delta Update). ### Negative 1. **Performance Overhead:** Forcing a `clear cache` on the UI Refresh button is more resource-intensive than a delta update, potentially leading to slightly longer loading spinners for users with large mailboxes. diff --git a/lib/features/caching/caching_manager.dart b/lib/features/caching/caching_manager.dart index 7e06bd05d..fcb650864 100644 --- a/lib/features/caching/caching_manager.dart +++ b/lib/features/caching/caching_manager.dart @@ -104,6 +104,7 @@ class CachingManager { _oidcConfigurationCacheManager.clear(), _tokenOidcCacheManager.clear(), _authenticationInfoCacheManager.clear(), + _encryptionKeyCacheManager.clear(), ], eagerError: true); } catch (e) { logWarning('CachingManager::clearAccountDataCached: Cannot clear account data cache: $e'); diff --git a/lib/features/login/data/local/encryption_key_cache_manager.dart b/lib/features/login/data/local/encryption_key_cache_manager.dart index 41ec7ff63..b1d5bf7dd 100644 --- a/lib/features/login/data/local/encryption_key_cache_manager.dart +++ b/lib/features/login/data/local/encryption_key_cache_manager.dart @@ -18,6 +18,11 @@ class EncryptionKeyCacheManager extends CacheManagerInteraction { return _encryptionKeyCacheClient.getItem(EncryptionKeyCache.keyCacheValue); } + Future clear() { + return _encryptionKeyCacheClient + .deleteItem(EncryptionKeyCache.keyCacheValue); + } + @override Future migrateHiveToIsolatedHive() async { try { diff --git a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart index 289711b6c..b60d7d7d2 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -617,6 +617,7 @@ class MailboxDashBoardController extends ReloadableController if (shouldPrevent) { event.preventDefault(); + return; } if (PlatformInfo.isWeb) {