Use querystorageAt for map entries (optional) (#2119)

This commit is contained in:
Jaco Greeff
2020-03-31 09:17:36 +02:00
committed by GitHub
parent ef9cd6fc4b
commit 0bdbf4b7a7
2 changed files with 13 additions and 8 deletions
+9 -7
View File
@@ -41,7 +41,7 @@ interface MetaDecoration {
type LinkageData = ITuple<[Codec, Linkage<Codec>]>;
const PAGE_SIZE_KEYS = 256;
const PAGE_SIZE_VALS = PAGE_SIZE_KEYS / 2;
const PAGE_SIZE_VALS = PAGE_SIZE_KEYS;
const l = logger('api/init');
@@ -248,6 +248,7 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.forEach(([_, { method, section }]): void => {
delete (this._rpc as any)[section][method];
delete (this._rpcCore as any)[section][method];
delete (this._rx.rpc as any)[section][method];
});
}
@@ -502,12 +503,13 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
combineLatest([
of(keys),
from(Array(Math.ceil(keys.length / PAGE_SIZE_VALS)).fill(0)).pipe(
// FIXME New RPC to take care of this in the works...
concatMap((_, index): Observable<Option<Raw>[]> =>
this._rpcCore.state.subscribeStorage<Option<Raw>[]>(
keys.slice(index * PAGE_SIZE_VALS, (index * PAGE_SIZE_VALS) + PAGE_SIZE_VALS)
).pipe(take(1))
),
concatMap((_, index): Observable<Option<Raw>[]> => {
const keyset = keys.slice(index * PAGE_SIZE_VALS, (index * PAGE_SIZE_VALS) + PAGE_SIZE_VALS);
return this._rpcCore.state.queryStorageAt
? this._rpcCore.state.queryStorageAt<Option<Raw>[]>(keyset)
: this._rpcCore.state.subscribeStorage<Option<Raw>[]>(keyset).pipe(take(1));
}),
toArray(),
map((valsArr: Option<Raw>[][]): Option<Raw>[] =>
valsArr.reduce((result: Option<Raw>[], vals): Option<Raw>[] =>