From afb6cd50b64d4afaa731a73ef0fd55423919ee25 Mon Sep 17 00:00:00 2001 From: jstashh <19509999+jstashh@users.noreply.github.com> Date: Thu, 11 Nov 2021 15:05:44 +0000 Subject: [PATCH] fix: filter cache responses in memory (#161) --- src/interfaces/ironbank.ts | 16 ++++++++++++---- src/interfaces/vault.ts | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/interfaces/ironbank.ts b/src/interfaces/ironbank.ts index b907ef20..3e3277ea 100644 --- a/src/interfaces/ironbank.ts +++ b/src/interfaces/ironbank.ts @@ -32,9 +32,13 @@ export class IronBankInterface extends ServiceInterface { * @returns */ async get(addresses?: Address[], overrides?: CallOverrides): Promise { - const cached = await this.cachedFetcherGet.fetch(addresses ? `addresses=${addresses.join()}` : undefined); + const cached = await this.cachedFetcherGet.fetch(); if (cached) { - return cached; + if (addresses) { + return cached.filter(market => addresses.includes(market.address)); + } else { + return cached; + } } const assetsStatic = await this.yearn.services.lens.adapters.ironBank.assetsStatic(addresses, overrides); @@ -67,9 +71,13 @@ export class IronBankInterface extends ServiceInterface { * @returns */ async getDynamic(addresses?: Address[], overrides?: CallOverrides): Promise { - const cached = await this.cachedFetcherGetDynamic.fetch(addresses ? `addresses=${addresses.join()}` : undefined); + const cached = await this.cachedFetcherGetDynamic.fetch(); if (cached) { - return cached; + if (addresses) { + return cached.filter(market => addresses.includes(market.address)); + } else { + return cached; + } } return await this.yearn.services.lens.adapters.ironBank.assetsDynamic(addresses, overrides); diff --git a/src/interfaces/vault.ts b/src/interfaces/vault.ts index dd8cfb6e..ec2f87c8 100644 --- a/src/interfaces/vault.ts +++ b/src/interfaces/vault.ts @@ -41,9 +41,13 @@ export class VaultInterface extends ServiceInterface { * @returns */ async get(addresses?: Address[], overrides?: CallOverrides): Promise { - const cached = await this.cachedFetcherGet.fetch(addresses ? `addresses=${addresses.join()}` : undefined); + const cached = await this.cachedFetcherGet.fetch(); if (cached) { - return cached; + if (addresses) { + return cached.filter(vault => addresses.includes(vault.address)); + } else { + return cached; + } } const vaultMetadataOverridesPromise = this.yearn.services.meta.vaults().catch(error => { @@ -134,9 +138,13 @@ export class VaultInterface extends ServiceInterface { vaultMetadataOverrides?: VaultMetadataOverrides[], overrides?: CallOverrides ): Promise { - const cached = await this.cachedFetcherGetDynamic.fetch(addresses ? `addresses=${addresses.join()}` : undefined); + const cached = await this.cachedFetcherGetDynamic.fetch(); if (cached) { - return cached; + if (addresses) { + return cached.filter(vault => addresses.includes(vault.address)); + } else { + return cached; + } } let metadataOverrides = vaultMetadataOverrides