Skip to content

Commit

Permalink
slice saving to avoid insanely large query that will fail
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-aurele-besner committed Aug 28, 2024
1 parent 441197f commit 48fae87
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions indexers/staking-squid/src/utils/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,13 @@ const saveEntry = async <E extends Entity>(
const entity = cache[name] as unknown as Map<string, E>;
if (entity.size === 0) return;

const entitiesArray = Array.from(entity.values());
const batchSize = 500;
const batches = [];
const entitiesArray = Array.from(entity.values()) as E[];
const batchSize = 300;

for (let i = 0; i < entitiesArray.length; i += batchSize) {
batches.push(entitiesArray.slice(i, i + batchSize));
const batch = entitiesArray.slice(i, i + batchSize);
await ctx.store.save(batch);
}

await Promise.all(batches.map((batch) => ctx.store.save(batch)));
} catch (e) {
console.error(`Failed to save ${name} with error:`, e);
}
Expand Down

0 comments on commit 48fae87

Please sign in to comment.