From 74ca8e1e07362a4b810fc3b530caeed66e905758 Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 3 Feb 2023 18:17:39 -0600 Subject: [PATCH] add delete address labels and tx notes functionality (isar notes unimplemented atm) --- lib/db/main_db.dart | 52 +++++++++++++++++++++++++------ lib/services/wallets_service.dart | 2 ++ 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/lib/db/main_db.dart b/lib/db/main_db.dart index 5e3d94a97..87885d09b 100644 --- a/lib/db/main_db.dart +++ b/lib/db/main_db.dart @@ -257,30 +257,62 @@ class MainDB { // transactions for (int i = 0; i < transactionCount; i += paginateLimit) { - final txns = await getTransactions(walletId) + final txnIds = await getTransactions(walletId) .offset(i) .limit(paginateLimit) + .idProperty() .findAll(); - await isar.transactions - .deleteAll(txns.map((e) => e.id).toList(growable: false)); + await isar.transactions.deleteAll(txnIds); } // addresses for (int i = 0; i < addressCount; i += paginateLimit) { - final addresses = await getAddresses(walletId) + final addressIds = await getAddresses(walletId) .offset(i) .limit(paginateLimit) + .idProperty() .findAll(); - await isar.addresses - .deleteAll(addresses.map((e) => e.id).toList(growable: false)); + await isar.addresses.deleteAll(addressIds); } // utxos for (int i = 0; i < utxoCount; i += paginateLimit) { - final utxos = - await getUTXOs(walletId).offset(i).limit(paginateLimit).findAll(); - await isar.utxos - .deleteAll(utxos.map((e) => e.id).toList(growable: false)); + final utxoIds = await getUTXOs(walletId) + .offset(i) + .limit(paginateLimit) + .idProperty() + .findAll(); + await isar.utxos.deleteAll(utxoIds); + } + }); + } + + Future deleteAddressLabels(String walletId) async { + final addressLabelCount = await getAddressLabels(walletId).count(); + await isar.writeTxn(() async { + const paginateLimit = 50; + for (int i = 0; i < addressLabelCount; i += paginateLimit) { + final labelIds = await getAddressLabels(walletId) + .offset(i) + .limit(paginateLimit) + .idProperty() + .findAll(); + await isar.addressLabels.deleteAll(labelIds); + } + }); + } + + Future deleteTransactionNotes(String walletId) async { + final noteCount = await getTransactionNotes(walletId).count(); + await isar.writeTxn(() async { + const paginateLimit = 50; + for (int i = 0; i < noteCount; i += paginateLimit) { + final labelIds = await getTransactionNotes(walletId) + .offset(i) + .limit(paginateLimit) + .idProperty() + .findAll(); + await isar.transactionNotes.deleteAll(labelIds); } }); } diff --git a/lib/services/wallets_service.dart b/lib/services/wallets_service.dart index 41bfd477f..3a9c99346 100644 --- a/lib/services/wallets_service.dart +++ b/lib/services/wallets_service.dart @@ -388,6 +388,8 @@ class WalletsService extends ChangeNotifier { // delete wallet data in main db await MainDB.instance.deleteWalletBlockchainData(walletId); + await MainDB.instance.deleteAddressLabels(walletId); + await MainDB.instance.deleteTransactionNotes(walletId); // box data may currently still be read/written to if wallet was refreshing // when delete was requested so instead of deleting now we mark the wallet