Additional derive cleanups (#4307)

* Additional derive cleanups

* Adjust

* Multi cache set

* Adjust mapping
This commit is contained in:
Jaco
2021-12-09 12:12:05 +02:00
committed by GitHub
parent 584cbb994b
commit e32ac213b9
21 changed files with 129 additions and 154 deletions
+13
View File
@@ -25,3 +25,16 @@ export function getEraMultiCache <T> (CACHE_KEY: string, eras: EraIndex[], withA
return cached;
}
export function setEraMultiCache <T extends { era: EraIndex }> (CACHE_KEY: string, withActive: boolean, values: T[]): T[] {
!withActive && values.forEach((v) => deriveCache.set(`${CACHE_KEY}-${v.era.toString()}`, v));
return values;
}
export function filterCachedEras <T extends { era: EraIndex }> (eras: EraIndex[], cached: T[], query: T[]): T[] {
return eras.map((e) =>
cached.find(({ era }) => e.eq(era)) ||
query.find(({ era }) => e.eq(era)) as T
);
}