From 0f5fe958cae6e1ec9a13173e2130f17edfd058a5 Mon Sep 17 00:00:00 2001 From: Tim Robinson Date: Wed, 9 Aug 2023 19:05:19 +1000 Subject: [PATCH] Fix resetting skip variable when loading pools from Balancer API The skip value is used in two ways: To keep track of where in the cache the frontend has loaded up to when repeatedly loading from the cache, or to track where in the API it's up to if loading from the API. There was a bug where when reading from the API it would call the read from cache at the end and this would reset the skip variable to the end of the cache instead of the end of the API list. This meant that when returning a filtered list of items from the API it would request say 1000 items, but only get 90 (because of the filter), then it would set set the skip for next time to 1000 (the total requested) when the skip should have actually been 90. This fixes that bug by only resetting the skip variable to the requested skip amount when fetching from the cache. It keeps the skip set to the total retrieved from the API when results have come from the API. --- balancer-js/src/modules/data/pool/balancer-api.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/balancer-js/src/modules/data/pool/balancer-api.ts b/balancer-js/src/modules/data/pool/balancer-api.ts index f89ad2618..d0c1b8166 100644 --- a/balancer-js/src/modules/data/pool/balancer-api.ts +++ b/balancer-js/src/modules/data/pool/balancer-api.ts @@ -67,7 +67,6 @@ export class PoolsBalancerAPIRepository const skip = options?.skip || DEFAULT_SKIP; const pools = this.pools.slice(skip, first + skip); - this.skip = skip + first; return pools; } @@ -77,7 +76,10 @@ export class PoolsBalancerAPIRepository this.pools.length > (options?.first || DEFAULT_FIRST) + (options?.skip || DEFAULT_SKIP) ) { - return this.fetchFromCache(options); + const cachedPools = this.fetchFromCache(options); + this.skip = + (options?.first || DEFAULT_FIRST) + (options?.skip || DEFAULT_SKIP); + return cachedPools; } if (this.nextToken) {