improve SWB restore performance when a large number of wallets is involved

This commit is contained in:
julian 2024-12-03 15:00:25 -06:00
parent 840b6f9c99
commit 86e3bf0349
2 changed files with 12 additions and 8 deletions

View file

@ -458,7 +458,7 @@ abstract class SWB {
mnemonic: mnemonic,
mnemonicPassphrase: mnemonicPassphrase,
);
Wallet? wallet;
try {
String? serializedKeys;
String? multisigConfig;
@ -491,7 +491,7 @@ abstract class SWB {
});
}
final wallet = await Wallet.create(
wallet = await Wallet.create(
walletInfo: info,
mainDB: MainDB.instance,
secureStorageInterface: secureStorageInterface,
@ -614,6 +614,8 @@ abstract class SWB {
mnemonicPassphrase: mnemonicPassphrase,
);
return false;
} finally {
await wallet?.exit();
}
return true;
}

View file

@ -701,7 +701,7 @@ class EpiccashWallet extends Bip39Wallet {
isar: mainDB.isar,
);
unawaited(_startScans());
unawaited(refresh(doScan: true));
} else {
await updateNode();
final String password = generatePassword();
@ -759,9 +759,8 @@ class EpiccashWallet extends Bip39Wallet {
epicData.receivingIndex,
);
}
unawaited(refresh(doScan: false));
});
unawaited(refresh());
} catch (e, s) {
Logging.instance.log(
"Exception rethrown from electrumx_mixin recover(): $e\n$s",
@ -773,7 +772,7 @@ class EpiccashWallet extends Bip39Wallet {
}
@override
Future<void> refresh() async {
Future<void> refresh({bool doScan = true}) async {
// Awaiting this lock could be dangerous.
// Since refresh is periodic (generally)
if (refreshMutex.isLocked) {
@ -803,9 +802,11 @@ class EpiccashWallet extends Bip39Wallet {
final int curAdd = await _getCurrentIndex();
await _generateAndStoreReceivingAddressForIndex(curAdd);
await _startScans();
if (doScan) {
await _startScans();
unawaited(_startSync());
unawaited(_startSync());
}
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.0, walletId));
await updateChainHeight();
@ -1157,6 +1158,7 @@ class EpiccashWallet extends Bip39Wallet {
@override
Future<void> exit() async {
epiccash.LibEpiccash.stopEpicboxListener();
timer?.cancel();
timer = null;
await super.exit();