diff options
author | Florian Dold <florian@dold.me> | 2021-08-06 17:15:46 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-08-06 17:15:46 +0200 |
commit | 06db37640e9932f9d2595ffa7c3cefe2204326db (patch) | |
tree | 55aebb32b6516b5287f6df892360503ea5f5433b /packages/taler-wallet-core/src/util | |
parent | 05e52d4e116222728d9bcba3bcbf9e441bb4e4ed (diff) | |
download | wallet-core-06db37640e9932f9d2595ffa7c3cefe2204326db.tar.xz |
perf: do bulk read
Diffstat (limited to 'packages/taler-wallet-core/src/util')
-rw-r--r-- | packages/taler-wallet-core/src/util/query.ts | 11 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/util/timer.ts | 11 |
2 files changed, 16 insertions, 6 deletions
diff --git a/packages/taler-wallet-core/src/util/query.ts b/packages/taler-wallet-core/src/util/query.ts index b76bf6b6b..a95cbf1ff 100644 --- a/packages/taler-wallet-core/src/util/query.ts +++ b/packages/taler-wallet-core/src/util/query.ts @@ -35,6 +35,7 @@ import { IDBKeyPath, } from "@gnu-taler/idb-bridge"; import { Logger } from "@gnu-taler/taler-util"; +import { performanceNow } from "./timer.js"; const logger = new Logger("query.ts"); @@ -298,6 +299,7 @@ export function describeIndex( interface IndexReadOnlyAccessor<RecordType> { iter(query?: IDBValidKey): ResultStream<RecordType>; get(query: IDBValidKey): Promise<RecordType | undefined>; + getAll(query: IDBValidKey, count?: number): Promise<RecordType[]>; } type GetIndexReadOnlyAccess<RecordType, IndexMap> = { @@ -307,6 +309,7 @@ type GetIndexReadOnlyAccess<RecordType, IndexMap> = { interface IndexReadWriteAccessor<RecordType> { iter(query: IDBValidKey): ResultStream<RecordType>; get(query: IDBValidKey): Promise<RecordType | undefined>; + getAll(query: IDBValidKey, count?: number): Promise<RecordType[]>; } type GetIndexReadWriteAccess<RecordType, IndexMap> = { @@ -484,6 +487,10 @@ function makeReadContext( .openCursor(query); return new ResultStream<any>(req); }, + getAll(query, count) { + const req = tx.objectStore(storeName).index(indexName).getAll(query, count); + return requestToPromise(req); + } }; } ctx[storeAlias] = { @@ -526,6 +533,10 @@ function makeWriteContext( .openCursor(query); return new ResultStream<any>(req); }, + getAll(query, count) { + const req = tx.objectStore(storeName).index(indexName).getAll(query, count); + return requestToPromise(req); + } }; } ctx[storeAlias] = { diff --git a/packages/taler-wallet-core/src/util/timer.ts b/packages/taler-wallet-core/src/util/timer.ts index a7fe7dd70..7c849fbcc 100644 --- a/packages/taler-wallet-core/src/util/timer.ts +++ b/packages/taler-wallet-core/src/util/timer.ts @@ -78,24 +78,23 @@ class TimeoutHandle { } /** - * Get a performance counter in milliseconds. + * Get a performance counter in nanoseconds. */ -export const performanceNow: () => number = (() => { +export const performanceNow: () => bigint = (() => { // @ts-ignore if (typeof process !== "undefined" && process.hrtime) { return () => { - const t = process.hrtime(); - return t[0] * 1e9 + t[1]; + return process.hrtime.bigint(); }; } // @ts-ignore if (typeof performance !== "undefined") { // @ts-ignore - return () => performance.now(); + return () => BigInt(performance.now()) * BigInt(1000 * 1000); } - return () => 0; + return () => BigInt(0); })(); /** |