[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] branch master updated: wallet-core: prepare for canc
From: |
gnunet |
Subject: |
[taler-wallet-core] branch master updated: wallet-core: prepare for cancellable DB access handle |
Date: |
Tue, 23 Apr 2024 00:43:34 +0200 |
This is an automated email from the git hooks/post-receive script.
dold pushed a commit to branch master
in repository wallet-core.
The following commit(s) were added to refs/heads/master by this push:
new f4ffd0fab wallet-core: prepare for cancellable DB access handle
f4ffd0fab is described below
commit f4ffd0fab12dadc709d6ced5d3129e0a2c03d72b
Author: Florian Dold <florian@dold.me>
AuthorDate: Tue Apr 23 00:43:29 2024 +0200
wallet-core: prepare for cancellable DB access handle
---
packages/taler-wallet-core/src/db.ts | 29 ++++++++++++++++++-------
packages/taler-wallet-core/src/query.ts | 8 ++++++-
packages/taler-wallet-core/src/wallet.ts | 36 ++++++++++++++++++++++++--------
3 files changed, 56 insertions(+), 17 deletions(-)
diff --git a/packages/taler-wallet-core/src/db.ts
b/packages/taler-wallet-core/src/db.ts
index 5bab70968..5da8518ea 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -34,6 +34,7 @@ import {
Amounts,
AttentionInfo,
BackupProviderTerms,
+ CancellationToken,
Codec,
CoinEnvelope,
CoinPublicKeyString,
@@ -3269,7 +3270,12 @@ export async function openStoredBackupsDatabase(
onStoredBackupsDbUpgradeNeeded,
);
- const handle = new DbAccessImpl(backupsDbHandle, StoredBackupStores);
+ const handle = new DbAccessImpl(
+ backupsDbHandle,
+ StoredBackupStores,
+ {},
+ CancellationToken.CONTINUE,
+ );
return handle;
}
@@ -3283,7 +3289,7 @@ export async function openStoredBackupsDatabase(
export async function openTalerDatabase(
idbFactory: IDBFactory,
onVersionChange: () => void,
-): Promise<DbAccess<typeof WalletStoresV1>> {
+): Promise<IDBDatabase> {
const metaDbHandle = await openDatabase(
idbFactory,
TALER_WALLET_META_DB_NAME,
@@ -3292,7 +3298,12 @@ export async function openTalerDatabase(
onMetaDbUpgradeNeeded,
);
- const metaDb = new DbAccessImpl(metaDbHandle, walletMetadataStore);
+ const metaDb = new DbAccessImpl(
+ metaDbHandle,
+ walletMetadataStore,
+ {},
+ CancellationToken.CONTINUE,
+ );
let currentMainVersion: string | undefined;
await metaDb.runReadWriteTx(["metaConfig"], async (tx) => {
const dbVersionRecord = await tx.metaConfig.get(CURRENT_DB_CONFIG_KEY);
@@ -3341,11 +3352,15 @@ export async function openTalerDatabase(
onTalerDbUpgradeNeeded,
);
- const handle = new DbAccessImpl(mainDbHandle, WalletStoresV1);
-
- await applyFixups(handle);
+ const mainDbAccess = new DbAccessImpl(
+ mainDbHandle,
+ WalletStoresV1,
+ {},
+ CancellationToken.CONTINUE,
+ );
+ await applyFixups(mainDbAccess);
- return handle;
+ return mainDbHandle;
}
export async function deleteTalerDatabase(
diff --git a/packages/taler-wallet-core/src/query.ts
b/packages/taler-wallet-core/src/query.ts
index d78e9bc6e..bdc8df0c7 100644
--- a/packages/taler-wallet-core/src/query.ts
+++ b/packages/taler-wallet-core/src/query.ts
@@ -35,7 +35,12 @@ import {
IDBValidKey,
IDBVersionChangeEvent,
} from "@gnu-taler/idb-bridge";
-import { Codec, Logger, openPromise } from "@gnu-taler/taler-util";
+import {
+ CancellationToken,
+ Codec,
+ Logger,
+ openPromise,
+} from "@gnu-taler/taler-util";
const logger = new Logger("query.ts");
@@ -814,6 +819,7 @@ export class DbAccessImpl<StoreMap> implements
DbAccess<StoreMap> {
private db: IDBDatabase,
private stores: StoreMap,
private triggers: TriggerSpec = {},
+ private cancellationToken: CancellationToken,
) {}
idbHandle(): IDBDatabase {
diff --git a/packages/taler-wallet-core/src/wallet.ts
b/packages/taler-wallet-core/src/wallet.ts
index f743e82b1..9f9b90446 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -22,7 +22,7 @@
/**
* Imports.
*/
-import { IDBFactory } from "@gnu-taler/idb-bridge";
+import { IDBDatabase, IDBFactory } from "@gnu-taler/idb-bridge";
import {
AbsoluteTime,
ActiveTask,
@@ -243,7 +243,7 @@ import {
checkPeerPushDebit,
initiatePeerPushDebit,
} from "./pay-peer-push-debit.js";
-import { DbAccess } from "./query.js";
+import { DbAccess, DbAccessImpl } from "./query.js";
import { forceRefresh } from "./refresh.js";
import {
TaskScheduler,
@@ -1020,7 +1020,7 @@ async function dispatchRequestInternal<Op extends
WalletApiOperation>(
const tasksInfo = await Promise.all(
allTasksId.map(async (id) => {
- return await wex.ws.db.runReadOnlyTx(
+ return await wex.db.runReadOnlyTx(
["operationRetries"],
async (tx) => {
return tx.operationRetries.get(id);
@@ -1758,15 +1758,19 @@ export class InternalWalletState {
private _config: Readonly<WalletRunConfig> | undefined;
- private _db: DbAccess<typeof WalletStoresV1> | undefined = undefined;
+ private _indexedDbHandle: IDBDatabase | undefined = undefined;
+
+ private _dbAccessHandle: DbAccess<typeof WalletStoresV1> | undefined;
private _http: HttpRequestLibrary | undefined = undefined;
get db(): DbAccess<typeof WalletStoresV1> {
- if (!this._db) {
- throw Error("db not initialized");
+ if (!this._dbAccessHandle) {
+ this._dbAccessHandle = this.createDbAccessHandle(
+ CancellationToken.CONTINUE,
+ );
}
- return this._db;
+ return this._dbAccessHandle;
}
devExperimentState: DevExperimentState = {};
@@ -1791,6 +1795,20 @@ export class InternalWalletState {
}
}
+ createDbAccessHandle(
+ cancellationToken: CancellationToken,
+ ): DbAccess<typeof WalletStoresV1> {
+ if (!this._indexedDbHandle) {
+ throw Error("db not initialized");
+ }
+ return new DbAccessImpl(
+ this._indexedDbHandle,
+ WalletStoresV1,
+ {},
+ cancellationToken,
+ );
+ }
+
get config(): WalletRunConfig {
if (!this._config) {
throw Error("config not initialized");
@@ -1817,7 +1835,7 @@ export class InternalWalletState {
}
async ensureWalletDbOpen(): Promise<void> {
- if (this._db) {
+ if (this._indexedDbHandle) {
return;
}
const myVersionChange = async (): Promise<void> => {
@@ -1825,7 +1843,7 @@ export class InternalWalletState {
};
try {
const myDb = await openTalerDatabase(this.idb, myVersionChange);
- this._db = myDb;
+ this._indexedDbHandle = myDb;
} catch (e) {
logger.error("error writing to database during initialization");
throw TalerError.fromDetail(TalerErrorCode.WALLET_DB_UNAVAILABLE, {
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-wallet-core] branch master updated: wallet-core: prepare for cancellable DB access handle,
gnunet <=