Skip to content

Commit

Permalink
fix: filter cache responses in memory (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstashh authored Nov 11, 2021
1 parent f60481a commit afb6cd5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
16 changes: 12 additions & 4 deletions src/interfaces/ironbank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ export class IronBankInterface<T extends ChainId> extends ServiceInterface<T> {
* @returns
*/
async get(addresses?: Address[], overrides?: CallOverrides): Promise<IronBankMarket[]> {
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);
Expand Down Expand Up @@ -67,9 +71,13 @@ export class IronBankInterface<T extends ChainId> extends ServiceInterface<T> {
* @returns
*/
async getDynamic(addresses?: Address[], overrides?: CallOverrides): Promise<IronBankMarketDynamic[]> {
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);
Expand Down
16 changes: 12 additions & 4 deletions src/interfaces/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ export class VaultInterface<T extends ChainId> extends ServiceInterface<T> {
* @returns
*/
async get(addresses?: Address[], overrides?: CallOverrides): Promise<Vault[]> {
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 => {
Expand Down Expand Up @@ -134,9 +138,13 @@ export class VaultInterface<T extends ChainId> extends ServiceInterface<T> {
vaultMetadataOverrides?: VaultMetadataOverrides[],
overrides?: CallOverrides
): Promise<VaultDynamic[]> {
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
Expand Down

0 comments on commit afb6cd5

Please sign in to comment.