Skip to content

Commit

Permalink
Apply memo(...) on batched storage subscriptions (#5435)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr committed Jan 20, 2023
1 parent 6f8ca71 commit 95e7edd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/api/src/base/Decorate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ export abstract class Decorate<ApiType extends ApiTypes> 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];
Expand Down Expand Up @@ -871,15 +871,17 @@ export abstract class Decorate<ApiType extends ApiTypes> 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<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): ReturnType<DecorateMethod<ApiType>> {
return decorateMethod((...args: unknown[]): Observable<Codec> => {
const memoed = memo(this.#instanceId, (...args: unknown[]): Observable<Codec> => {
const call = extractStorageArgs(this.#registry, creator, args);

if (!this.hasSubscriptions) {
return this._rpcCore.state.getStorage(call);
}

return this._queueStorage(call, this.#storageSubQ);
}, {
});

return decorateMethod(memoed, {
methodName: creator.method,
overrideNoSub: (...args: unknown[]) =>
this._queueStorage(extractStorageArgs(this.#registry, creator, args), this.#storageGetQ)
Expand Down

0 comments on commit 95e7edd

Please sign in to comment.