From d36b1304389cf038bd7c927806bda8432de21849 Mon Sep 17 00:00:00 2001 From: Domino Valdano <2644901+reductionista@users.noreply.github.com> Date: Wed, 17 Jul 2024 11:06:49 -0700 Subject: [PATCH] WIP --- core/chains/evm/logpoller/orm.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/core/chains/evm/logpoller/orm.go b/core/chains/evm/logpoller/orm.go index 0550b524f4..81cf064e1a 100644 --- a/core/chains/evm/logpoller/orm.go +++ b/core/chains/evm/logpoller/orm.go @@ -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 @@ -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