|
8 | 8 | if TYPE_CHECKING: |
9 | 9 | from dipdup.datasources.tezos_tzkt import TezosTzktDatasource |
10 | 10 |
|
| 11 | +BATCH_SIZE = 1000 |
| 12 | + |
11 | 13 |
|
12 | 14 | async def check_expiration( |
13 | 15 | ctx: HookContext, |
14 | 16 | ) -> None: |
15 | 17 | ds = cast('TezosTzktDatasource', next(iter(ctx.datasources.values()))) |
16 | | - expiring_records = ( |
17 | | - await Record.filter(expired=False, domain__expires_at__lt=datetime.utcnow()).all().prefetch_related('domain') |
18 | | - ) |
19 | | - |
20 | | - for record in expiring_records: |
21 | | - ctx.logger.info('Record %s expired at %s', record.id, record.domain.expires_at) |
22 | | - record.expired = True |
23 | | - await record.save() |
24 | | - if record.address: |
25 | | - ctx.logger.debug('Invalidating contract metadata for %s @ %s', record.address, record.id) |
26 | | - await ctx.update_contract_metadata( |
27 | | - network=ds.name, |
28 | | - address=record.address, |
29 | | - metadata={}, # TODO: NULL |
30 | | - ) |
| 18 | + total_processed = 0 |
| 19 | + |
| 20 | + while True: |
| 21 | + expiring_records = ( |
| 22 | + await Record.filter(expired=False, domain__expires_at__lt=datetime.utcnow()) |
| 23 | + .limit(BATCH_SIZE) |
| 24 | + .prefetch_related('domain') |
| 25 | + ) |
| 26 | + |
| 27 | + if not expiring_records: |
| 28 | + break |
| 29 | + |
| 30 | + for record in expiring_records: |
| 31 | + ctx.logger.info('Record %s expired at %s', record.id, record.domain.expires_at) |
| 32 | + record.expired = True |
| 33 | + await record.save() |
| 34 | + if record.address: |
| 35 | + ctx.logger.debug('Invalidating contract metadata for %s @ %s', record.address, record.id) |
| 36 | + await ctx.update_contract_metadata( |
| 37 | + network=ds.name, |
| 38 | + address=record.address, |
| 39 | + metadata={}, # TODO: NULL |
| 40 | + ) |
| 41 | + |
| 42 | + total_processed += len(expiring_records) |
| 43 | + ctx.logger.info('Processed %s expired records so far', total_processed) |
| 44 | + |
| 45 | + if total_processed: |
| 46 | + ctx.logger.info('Finished processing %s expired records', total_processed) |
0 commit comments