Skip to content

Commit 07b4698

Browse files
author
Zhouwb
committed
fix: 修复重启丢失数据问题
1 parent 2a1ca3a commit 07b4698

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed
Binary file not shown.

packages/default-storage/harmony/async_storage/src/main/ets/ReactDatabaseSupplier.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class ReactDatabaseSupplier {
3434
static KEY_COLUMN = "key";
3535
static VALUE_COLUMN = "value"
3636
private DATABASE_VERSION = 1;
37-
private SLEEP_TIME_MS = 30;
37+
private SLEEP_TIME_MS = 50;
3838
private VERSION_TABLE_CREATE =
3939
"CREATE TABLE IF NOT EXISTS " + ReactDatabaseSupplier.TABLE_CATALYST + " (" +
4040
ReactDatabaseSupplier.KEY_COLUMN + " TEXT PRIMARY KEY, " +
@@ -75,17 +75,18 @@ export default class ReactDatabaseSupplier {
7575

7676
async ensureDatabase(context: common.UIAbilityContext): Promise<boolean> {
7777
if(this.rdbStore !== null) return true;
78-
for(let tries = 0; tries < 2; tries++) {
79-
try {
80-
if(tries > 0) await this.deleteRdbStore(context);
81-
await this.initialRdbStore(context);
82-
} catch (e) {
83-
throw new Error(`Ensure database faile!`);
84-
}
85-
try {
86-
await this.sleep(this.SLEEP_TIME_MS)
87-
} catch (e) {
88-
throw new Error('Ensure database sleep fail')
78+
for(let tries = 0; tries < 3; tries++) {
79+
if(this.rdbStore === null){
80+
try {
81+
await this.initialRdbStore(context);
82+
} catch (e) {
83+
throw new Error(`Ensure database faile!`);
84+
}
85+
try {
86+
await this.sleep(this.SLEEP_TIME_MS)
87+
} catch (e) {
88+
throw new Error('Ensure database sleep fail')
89+
}
8990
}
9091
}
9192
if(this.rdbStore === null) {

0 commit comments

Comments
 (0)