Skip to content

Commit

Permalink
fix test cases, update logic in removal
Browse files Browse the repository at this point in the history
  • Loading branch information
bz888 committed Apr 17, 2024
1 parent d57f260 commit 14b2b5a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 0 additions & 1 deletion packages/node/src/utils/kyve/kyve.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ describe('KyveApi', () => {
const files = await fs.promises.readdir(tmpPath);

expect(files).not.toContain('bundle_0.json');
expect(files).not.toContain('bundle_1.json');
});
it('Should increment bundleId when height exceeds cache', async () => {
const bundle = await (kyveApi as any).getBundleById(0);
Expand Down
22 changes: 12 additions & 10 deletions packages/node/src/utils/kyve/kyve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,18 @@ export class KyveApi {

const currentBundle = this.getBundleFromCache(height);

return cachedBundles.filter((b) => {
const isNotCurrentBundleAndLower =
currentBundle.id !== b.id &&
parseDecimal(currentBundle.id) > parseDecimal(b.id);
const isOutsiderBuffer =
height < parseDecimal(b.from_key) - bufferSize ||
height > parseDecimal(b.to_key) + bufferSize;

return isNotCurrentBundleAndLower && isOutsiderBuffer;
});
return currentBundle
? cachedBundles.filter((b) => {
const isNotCurrentBundleAndLower =
currentBundle.id !== b.id &&
parseDecimal(currentBundle.id) > parseDecimal(b.id);
const isOutsiderBuffer =
height < parseDecimal(b.from_key) - bufferSize ||
height > parseDecimal(b.to_key) + bufferSize;

return isNotCurrentBundleAndLower && isOutsiderBuffer;
})
: [];
}

async clearFileCache(
Expand Down

0 comments on commit 14b2b5a

Please sign in to comment.