-
Notifications
You must be signed in to change notification settings - Fork 92
Fix cannot sync data between mobile and web #3750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hoangdat
merged 11 commits into
master
from
hotfix/cannot-sync-data-between-mobile-and-web
Jul 1, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
09ec388
Use default properties when update email from email changed
dab246 d12120d
Remove `closeBox` when open box in hive database
dab246 b1f0297
Increase debounce time receive FCM background message to 30s
dab246 33def59
Remove store state to refresh in FCM
dab246 d6a5eef
Auto refresh mails when resume app from background
dab246 64a6390
Use `Hive CE` database to replace `Hive` database
dab246 781c4ae
Fix missing `GetStoredEmailStateInteractor`
dab246 274f269
Fix cannot auto refresh when back to app
dab246 bcc1a56
Add unit test for combineEmailCache method
dab246 005ac8f
Migrate Hive box To IsolatedHive box
dab246 5abbb7a
Remove migrate boxes `Mailbox, Email, DetailEmail, State`
dab246 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# 66. Synchronize caching | ||
|
||
Date: 2025-06-18 | ||
|
||
## Status | ||
|
||
Accepted | ||
|
||
## Context | ||
|
||
Synchronizing server and database data is quite troublesome, | ||
when we use many protocols to receive mails (FCM, WebSocket, Memory operator). | ||
In addition, we are using `Hive` database to store data, | ||
it does not support multiple isolate to access the database. | ||
This leads to inconsistent database data, sometimes corrupted and lost data. | ||
|
||
## Decision | ||
|
||
To overcome this problem we need a database that can support multiple isolate. | ||
So we need to use [Hive_CE](https://pub.dev/packages/hive_ce) to replace `Hive` database. | ||
Hive CE is a spiritual continuation of Hive v2 with the following new features, such as: | ||
|
||
- Isolate support through IsolatedHive | ||
- Automatic type adapter generation using the GenerateAdapters annotation | ||
- No more manually adding annotations to every type and field | ||
- Generate adapters for classes outside the current package | ||
- A HiveRegistrar extension that lets you register all your generated adapters in one call | ||
- Extends the maximum type ID from 223 to 65439 | ||
... | ||
|
||
## Consequences | ||
|
||
- Data is always synchronized with the latest |
20 changes: 20 additions & 0 deletions
20
lib/features/base/upgradeable/upgrade_hive_database_steps_v17.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
import 'package:tmail_ui_user/features/base/upgradeable/upgrade_database_steps.dart'; | ||
import 'package:tmail_ui_user/features/caching/caching_manager.dart'; | ||
import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart'; | ||
|
||
class UpgradeHiveDatabaseStepsV17 extends UpgradeDatabaseSteps { | ||
|
||
final CachingManager _cachingManager; | ||
|
||
UpgradeHiveDatabaseStepsV17(this._cachingManager); | ||
|
||
@override | ||
Future<void> onUpgrade(int oldVersion, int newVersion) async { | ||
if (oldVersion > 0 && oldVersion < newVersion && newVersion == 17) { | ||
await HiveCacheConfig.instance.setUp(isolated: false); | ||
await _cachingManager.migrateHiveToIsolatedHive(); | ||
await _cachingManager.closeHive(isolated: false); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
class CacheVersion { | ||
static const int hiveDBVersion = 16; | ||
static const int hiveDBVersion = 17; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'dart:ui' as flutter; | ||
|
||
import 'package:hive_ce/hive.dart'; | ||
|
||
class FcmIsolateNameServer extends IsolateNameServer { | ||
const FcmIsolateNameServer(); | ||
|
||
@override | ||
dynamic lookupPortByName(String name) => | ||
flutter.IsolateNameServer.lookupPortByName(name); | ||
|
||
@override | ||
bool registerPortWithName(dynamic port, String name) => | ||
flutter.IsolateNameServer.registerPortWithName(port, name); | ||
|
||
@override | ||
bool removePortNameMapping(String name) => | ||
flutter.IsolateNameServer.removePortNameMapping(name); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.