From 7ef82c73900cf55dbf86dd1a57889bda7cb810d9 Mon Sep 17 00:00:00 2001 From: Kurdistan Tech Ministry Date: Sat, 11 Apr 2026 15:09:39 +0300 Subject: [PATCH] fix: paginate activeStakers cleanup with limit 100 (SubQuery max) --- src/mappings/PoolStakers.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/mappings/PoolStakers.ts b/src/mappings/PoolStakers.ts index 213ebb3..cf49d12 100644 --- a/src/mappings/PoolStakers.ts +++ b/src/mappings/PoolStakers.ts @@ -297,17 +297,24 @@ async function _computeAndSaveAPYInner(): Promise { // Remove ALL existing active stakers before refreshing with current era data. // This prevents stale entries from nominators who are no longer in the exposure set. + // SubQuery getByField max limit is 100 — paginate to remove all. try { - const existingStakers = await ActiveStaker.getByNetworkId( - PEZKUWI_ASSET_HUB_GENESIS, - { limit: 500 }, - ); - if (existingStakers && existingStakers.length > 0) { - for (const staker of existingStakers) { + let cleared = 0; + while (true) { + const batch = await ActiveStaker.getByNetworkId( + PEZKUWI_ASSET_HUB_GENESIS, + { limit: 100 }, + ); + if (!batch || batch.length === 0) break; + for (const staker of batch) { await ActiveStaker.remove(staker.id); } + cleared += batch.length; + if (batch.length < 100) break; + } + if (cleared > 0) { logger.info( - `Cleared ${existingStakers.length} stale active stakers for era ${currentEra}`, + `Cleared ${cleared} stale active stakers for era ${currentEra}`, ); } } catch (e) {