Skip to content

Commit

Permalink
Fix: opg query
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jul 10, 2023
1 parent 0a9d149 commit ecf321c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions internal/postgres/operation/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,15 @@ func (storage *Storage) OPG(address string, size, lastID int64) ([]operation.OPG
func(q *orm.Query) (*orm.Query, error) {
return q.Where("destination_id = ?", accountID).WhereOr("source_id = ?", accountID), nil
},
).
Order("id desc").
Limit(325)
)

if lastID > 0 {
subQuery.Where("id < ?", lastID)
}

var opg []operation.OPG
_, err := storage.DB.Query(&opg, `
with opg as (?)
select
ta.last_id,
ta.status,
Expand All @@ -278,14 +277,14 @@ func (storage *Storage) OPG(address string, size, lastID int64) ([]operation.OPG
from operations
where hash = ta.hash and counter = ta.counter),
ta.hash, operations.level, operations.timestamp, operations.entrypoint, operations.content_index from (
select min(id) as last_id, hash, counter, max(status) as status, min(kind) as kind from (?) as t
select min(id) as last_id, hash, counter, max(status) as status, min(kind) as kind from (select * from opg) as t
group by hash, counter
order by last_id desc
limit ?
) as ta
join operations on operations.id = ta.last_id
order by last_id desc
`, accountID, subQuery, limit)
`, subQuery, accountID, limit)
return opg, err
}

Expand Down

0 comments on commit ecf321c

Please sign in to comment.