Skip to content

Commit 95e7edd

Browse files
authored
Apply memo(...) on batched storage subscriptions (#5435)
1 parent 6f8ca71 commit 95e7edd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/api/src/base/Decorate.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
842842
nextTick((): void => {
843843
// get all the calls in this instance, resolve with it
844844
// and then clear the queue so we don't add more
845-
// (anyhting after this will be added to a new queue)
845+
// (anything after this will be added to a new queue)
846846
const calls = queue[queueIdx][1];
847847

848848
delete queue[queueIdx];
@@ -871,15 +871,17 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
871871
// Decorate the base storage call. In the case or rxjs or promise-without-callback (await)
872872
// we make a subscription, alternatively we push this through a single-shot query
873873
private _decorateStorageCall<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): ReturnType<DecorateMethod<ApiType>> {
874-
return decorateMethod((...args: unknown[]): Observable<Codec> => {
874+
const memoed = memo(this.#instanceId, (...args: unknown[]): Observable<Codec> => {
875875
const call = extractStorageArgs(this.#registry, creator, args);
876876

877877
if (!this.hasSubscriptions) {
878878
return this._rpcCore.state.getStorage(call);
879879
}
880880

881881
return this._queueStorage(call, this.#storageSubQ);
882-
}, {
882+
});
883+
884+
return decorateMethod(memoed, {
883885
methodName: creator.method,
884886
overrideNoSub: (...args: unknown[]) =>
885887
this._queueStorage(extractStorageArgs(this.#registry, creator, args), this.#storageGetQ)

0 commit comments

Comments
 (0)