Skip to content

Commit

Permalink
Rename LogIds & some changes to orm_test.go from chainlink repo
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Sep 24, 2024
1 parent 097aec6 commit d02e394
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
4 changes: 2 additions & 2 deletions core/chains/evm/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1116,11 +1116,11 @@ func (lp *logPoller) PruneExpiredLogs(ctx context.Context) (bool, error) {
}

func (lp *logPoller) PruneUnmatchedLogs(ctx context.Context) (bool, error) {
ids, err := lp.orm.SelectUnmatchedLogIds(ctx, lp.logPrunePageSize)
ids, err := lp.orm.SelectUnmatchedLogIDs(ctx, lp.logPrunePageSize)
if err != nil {
return false, err
}
rowsRemoved, err := lp.orm.DeleteLogsByRowId(ctx, ids)
rowsRemoved, err := lp.orm.DeleteLogsByRowID(ctx, ids)

return lp.logPrunePageSize == 0 || rowsRemoved < lp.logPrunePageSize, err
}
Expand Down
12 changes: 6 additions & 6 deletions core/chains/evm/logpoller/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ func (o *ObservedORM) DeleteLogsAndBlocksAfter(ctx context.Context, start int64)
})
}

func (o *ObservedORM) DeleteLogsByRowId(ctx context.Context, rowIds []uint64) (int64, error) {
return withObservedExecAndRowsAffected(o, "DeleteLogsByRowId", del, func() (int64, error) {
return o.ORM.DeleteLogsByRowId(ctx, rowIds)
func (o *ObservedORM) DeleteLogsByRowID(ctx context.Context, rowIDs []uint64) (int64, error) {
return withObservedExecAndRowsAffected(o, "DeleteLogsByRowID", del, func() (int64, error) {
return o.ORM.DeleteLogsByRowID(ctx, rowIDs)
})
}

func (o *ObservedORM) SelectUnmatchedLogIds(ctx context.Context, limit int64) (ids []uint64, err error) {
return withObservedQueryAndResults[uint64](o, "SelectUnmatchedLogIds", func() ([]uint64, error) {
return o.ORM.SelectUnmatchedLogIds(ctx, limit)
func (o *ObservedORM) SelectUnmatchedLogIDs(ctx context.Context, limit int64) (ids []uint64, err error) {
return withObservedQueryAndResults[uint64](o, "SelectUnmatchedLogIDs", func() ([]uint64, error) {
return o.ORM.SelectUnmatchedLogIDs(ctx, limit)
})
}

Expand Down
12 changes: 6 additions & 6 deletions core/chains/evm/logpoller/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ type ORM interface {
LoadFilters(ctx context.Context) (map[string]Filter, error)
DeleteFilter(ctx context.Context, name string) error

DeleteLogsByRowId(ctx context.Context, rowIds []uint64) (int64, error)
DeleteLogsByRowID(ctx context.Context, rowIDs []uint64) (int64, error)
InsertBlock(ctx context.Context, blockHash common.Hash, blockNumber int64, blockTimestamp time.Time, finalizedBlock int64) error
DeleteBlocksBefore(ctx context.Context, end int64, limit int64) (int64, error)
DeleteLogsAndBlocksAfter(ctx context.Context, start int64) error
SelectUnmatchedLogIds(ctx context.Context, limit int64) (ids []uint64, err error)
SelectUnmatchedLogIDs(ctx context.Context, limit int64) (ids []uint64, err error)
DeleteExpiredLogs(ctx context.Context, limit int64) (int64, error)

GetBlocksRange(ctx context.Context, start int64, end int64) ([]LogPollerBlock, error)
Expand Down Expand Up @@ -380,7 +380,7 @@ type Exp struct {
ShouldDelete bool
}

func (o *DSORM) SelectUnmatchedLogIds(ctx context.Context, limit int64) (ids []uint64, err error) {
func (o *DSORM) SelectUnmatchedLogIDs(ctx context.Context, limit int64) (ids []uint64, err error) {
query := `
SELECT l.id FROM evm.logs l JOIN (
SELECT evm_chain_id, address, event
Expand Down Expand Up @@ -1050,9 +1050,9 @@ func (o *DSORM) FilteredLogs(ctx context.Context, filter []query.Expression, lim
return logs, nil
}

// DeleteLogsByRowId accepts a list of log row id's to delete
func (o *DSORM) DeleteLogsByRowId(ctx context.Context, rowIds []uint64) (int64, error) {
result, err := o.ds.ExecContext(ctx, `DELETE FROM evm.logs WHERE id = ANY($1)`, rowIds)
// DeleteLogsByRowID accepts a list of log row id's to delete
func (o *DSORM) DeleteLogsByRowID(ctx context.Context, rowIDs []uint64) (int64, error) {
result, err := o.ds.ExecContext(ctx, `DELETE FROM evm.logs WHERE id = ANY($1)`, rowIDs)
if err != nil {
return 0, err
}
Expand Down
12 changes: 11 additions & 1 deletion core/chains/evm/logpoller/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,17 @@ func TestORM(t *testing.T) {
// Delete expired logs without page limit
deleted, err = o1.DeleteExpiredLogs(ctx, 0)
require.NoError(t, err)
assert.Equal(t, int64(2), deleted)
assert.Equal(t, int64(1), deleted)

// Delete unmatched logs with page limit
ids, err := o1.SelectUnmatchedLogIDs(ctx, 2)
require.NoError(t, err)
assert.Equal(t, int64(2), ids)

// Delete unmatched logs without page limit
ids, err = o1.SelectUnmatchedLogIDs(ctx, 0)
require.NoError(t, err)
assert.Equal(t, int64(2), ids)

// Ensure that both of the logs from the second chain are still there
logs, err = o2.SelectLogs(ctx, 0, 100, common.HexToAddress("0x1236"), topic2)
Expand Down

0 comments on commit d02e394

Please sign in to comment.