diff options
author | Florian Dold <florian@dold.me> | 2024-04-23 01:52:06 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-04-23 01:52:06 +0200 |
commit | 4b69853c347071acb73efcde9d4969cf06d0dfcc (patch) | |
tree | 01ed3cbf9d5939dc44f3ce6c31b71edd8dbdb43e /packages/taler-wallet-core/src/wallet.ts | |
parent | 5c0f03f102848d208248e1508f1da8316ebf6407 (diff) | |
download | wallet-core-4b69853c347071acb73efcde9d4969cf06d0dfcc.tar.xz |
wallet-core: simple DB trigger mechanism
Diffstat (limited to 'packages/taler-wallet-core/src/wallet.ts')
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 9f9b90446..810c78583 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -243,7 +243,12 @@ import { checkPeerPushDebit, initiatePeerPushDebit, } from "./pay-peer-push-debit.js"; -import { DbAccess, DbAccessImpl } from "./query.js"; +import { + AfterCommitInfo, + DbAccess, + DbAccessImpl, + TriggerSpec, +} from "./query.js"; import { forceRefresh } from "./refresh.js"; import { TaskScheduler, @@ -665,7 +670,7 @@ export interface PendingOperationsResponse { /** * Implementation of the "wallet-core" API. */ -async function dispatchRequestInternal<Op extends WalletApiOperation>( +async function dispatchRequestInternal( wex: WalletExecutionContext, cts: CancellationToken.Source, operation: WalletApiOperation, @@ -1713,6 +1718,34 @@ export class Cache<T> { } /** + * Implementation of triggers for the wallet DB. + */ +class WalletDbTriggerSpec implements TriggerSpec { + constructor(public ws: InternalWalletState) {} + + afterCommit(info: AfterCommitInfo): void { + if (info.mode !== "readwrite") { + return; + } + logger.info( + `in after commit callback for readwrite, modified ${j2s([ + ...info.modifiedStores, + ])}`, + ); + const modified = info.accessedStores; + if ( + modified.has(WalletStoresV1.exchanges.storeName) || + modified.has(WalletStoresV1.exchangeDetails.storeName) || + modified.has(WalletStoresV1.denominations.storeName) || + modified.has(WalletStoresV1.globalCurrencyAuditors.storeName) || + modified.has(WalletStoresV1.globalCurrencyExchanges.storeName) + ) { + this.ws.clearAllCaches(); + } + } +} + +/** * Internal state of the wallet. * * This ties together all the operation implementations. @@ -1804,7 +1837,7 @@ export class InternalWalletState { return new DbAccessImpl( this._indexedDbHandle, WalletStoresV1, - {}, + new WalletDbTriggerSpec(this), cancellationToken, ); } |