Skip to content

Commit 9c2bf30

Browse files
committed
fix account seeding for yield tracking
1 parent 676e533 commit 9c2bf30

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

src/templates/otoken/otoken-entity-producer.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import dayjs from 'dayjs'
22
import utc from 'dayjs/plugin/utc'
3+
import { chunk } from 'lodash'
34
import { In, LessThan } from 'typeorm'
45
import { parseUnits } from 'viem'
56

@@ -761,24 +762,16 @@ export class OTokenEntityProducer {
761762
}
762763
}
763764
}
765+
// Seed each account's latest prior yield row individually. A bulk
766+
// `address IN (...)` query here has no per-address LIMIT, so it pulls every
767+
// historical row for every account (one row per address per day) and blows
768+
// the heap once the holder set is large. `ensureYieldSeed` fetches a single
769+
// latest row per address; we run them in bounded-concurrency batches so the
770+
// point lookups stay fast without buffering a huge result set.
764771
if (accountsNeedingSeed.length > 0) {
765-
const rows = await this.ctx.store.find(OTokenAddressYield, {
766-
where: {
767-
chainId: this.ctx.chain.id,
768-
otoken: this.otoken.address,
769-
address: In(accountsNeedingSeed),
770-
},
771-
order: { date: 'DESC' },
772-
})
773-
const today = new Date(this.otoken.block.header.timestamp).toISOString().slice(0, 10)
774-
for (const row of rows) {
775-
if (row.date === today) {
776-
if (!this.currentDayAddressYieldRows.has(row.address)) {
777-
this.currentDayAddressYieldRows.set(row.address, row)
778-
}
779-
} else if (!this.previousDayAddressYieldRows.has(row.address)) {
780-
this.previousDayAddressYieldRows.set(row.address, row)
781-
}
772+
const SEED_CONCURRENCY = 50
773+
for (const batch of chunk(accountsNeedingSeed, SEED_CONCURRENCY)) {
774+
await Promise.all(batch.map((account) => this.ensureYieldSeed(account)))
782775
}
783776
}
784777

0 commit comments

Comments
 (0)