|
1 | 1 | import dayjs from 'dayjs' |
2 | 2 | import utc from 'dayjs/plugin/utc' |
| 3 | +import { chunk } from 'lodash' |
3 | 4 | import { In, LessThan } from 'typeorm' |
4 | 5 | import { parseUnits } from 'viem' |
5 | 6 |
|
@@ -761,24 +762,16 @@ export class OTokenEntityProducer { |
761 | 762 | } |
762 | 763 | } |
763 | 764 | } |
| 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. |
764 | 771 | 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))) |
782 | 775 | } |
783 | 776 | } |
784 | 777 |
|
|
0 commit comments