From 95e7edd48f1af171bd64407fce56a5e19e8ebb1c Mon Sep 17 00:00:00 2001 From: Jaco Date: Fri, 20 Jan 2023 23:26:45 +0200 Subject: [PATCH] Apply memo(...) on batched storage subscriptions (#5435) --- packages/api/src/base/Decorate.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/api/src/base/Decorate.ts b/packages/api/src/base/Decorate.ts index 1993f980f5..7f85a81a44 100644 --- a/packages/api/src/base/Decorate.ts +++ b/packages/api/src/base/Decorate.ts @@ -842,7 +842,7 @@ export abstract class Decorate extends Events { nextTick((): void => { // get all the calls in this instance, resolve with it // and then clear the queue so we don't add more - // (anyhting after this will be added to a new queue) + // (anything after this will be added to a new queue) const calls = queue[queueIdx][1]; delete queue[queueIdx]; @@ -871,7 +871,7 @@ export abstract class Decorate extends Events { // Decorate the base storage call. In the case or rxjs or promise-without-callback (await) // we make a subscription, alternatively we push this through a single-shot query private _decorateStorageCall (creator: StorageEntry, decorateMethod: DecorateMethod): ReturnType> { - return decorateMethod((...args: unknown[]): Observable => { + const memoed = memo(this.#instanceId, (...args: unknown[]): Observable => { const call = extractStorageArgs(this.#registry, creator, args); if (!this.hasSubscriptions) { @@ -879,7 +879,9 @@ export abstract class Decorate extends Events { } return this._queueStorage(call, this.#storageSubQ); - }, { + }); + + return decorateMethod(memoed, { methodName: creator.method, overrideNoSub: (...args: unknown[]) => this._queueStorage(extractStorageArgs(this.#registry, creator, args), this.#storageGetQ)