mirror of
https://github.com/pezkuwichain/pezkuwi-subquery.git
synced 2026-04-21 23:37:56 +00:00
fix: paginate activeStakers cleanup with limit 100 (SubQuery max)
This commit is contained in:
@@ -297,17 +297,24 @@ async function _computeAndSaveAPYInner(): Promise<void> {
|
|||||||
|
|
||||||
// Remove ALL existing active stakers before refreshing with current era data.
|
// 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.
|
// 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 {
|
try {
|
||||||
const existingStakers = await ActiveStaker.getByNetworkId(
|
let cleared = 0;
|
||||||
PEZKUWI_ASSET_HUB_GENESIS,
|
while (true) {
|
||||||
{ limit: 500 },
|
const batch = await ActiveStaker.getByNetworkId(
|
||||||
);
|
PEZKUWI_ASSET_HUB_GENESIS,
|
||||||
if (existingStakers && existingStakers.length > 0) {
|
{ limit: 100 },
|
||||||
for (const staker of existingStakers) {
|
);
|
||||||
|
if (!batch || batch.length === 0) break;
|
||||||
|
for (const staker of batch) {
|
||||||
await ActiveStaker.remove(staker.id);
|
await ActiveStaker.remove(staker.id);
|
||||||
}
|
}
|
||||||
|
cleared += batch.length;
|
||||||
|
if (batch.length < 100) break;
|
||||||
|
}
|
||||||
|
if (cleared > 0) {
|
||||||
logger.info(
|
logger.info(
|
||||||
`Cleared ${existingStakers.length} stale active stakers for era ${currentEra}`,
|
`Cleared ${cleared} stale active stakers for era ${currentEra}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user