Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Jul 30, 2024
1 parent d2c3538 commit d36b130
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions core/chains/evm/logpoller/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,11 @@ func (o *DSORM) DeleteExpiredLogs(ctx context.Context, limit int64) (int64, erro

// DeleteExcessLogs deletes any logs old enough that MaxLogsKept has been exceeded for every filter they match.
func (o *DSORM) DeleteExcessLogs(ctx context.Context) (int64, error) {
rowIds := struct {
EvmChainId ubig.Big
BlockHash common.Hash
LogIndex uint64
}{}
err := o.ds.GetContext(ctx, &rowIds, `
var rowIds []struct {
BlockNumber uint64
LogIndex uint64
}
err := o.ds.SelectContext(ctx, &rowIds, `
SELECT block_number, log_index FROM (
SELECT max_logs_kept != 0 AND ROW_NUMBER() OVER(PARTITION BY f.id ORDER BY block_number, log_index DESC) > max_logs_kept AS old, block_number, log_index
FROM evm.log_poller_filters f JOIN evm.logs l
Expand All @@ -366,7 +365,7 @@ func (o *DSORM) DeleteExcessLogs(ctx context.Context) (int64, error) {
return 0, err
}

result, err := o.ds.ExecContext(ctx, `DELETE FROM evm.logs WHERE block_hash=:block_hash AND log_index=:log_index AND evm_chain_id=5`, rowIds)
result, err := o.ds.ExecContext(ctx, `DELETE FROM evm.logs WHERE evm_chain_id = :evm_chain_id AND (block_number, log_index) IN rowIds`, rowIds)

if err != nil {
return 0, err
Expand Down

0 comments on commit d36b130

Please sign in to comment.