Skip to content

Commit

Permalink
TODO: fix slow query
Browse files Browse the repository at this point in the history
  • Loading branch information
millken committed May 13, 2022
1 parent 316bfae commit 7627a7c
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions apiservice/staking_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ func getVoteBucketParams(addr string, height, bucketID uint64) (uint32, bool, bo

func getCandidateStaking(height uint64, addr string) ([]*Staking, error) {
db := db.DB()
//TODO: fix the query, it's too slow
query := "select id,block_height,bucket_id,owner_address,candidate,(select sum(b.amount) from staking_actions b where b.block_height<=? and b.bucket_id=a.bucket_id) as amount,act_type,auto_stake,duration from staking_actions a where id=any(array(select max(id) from staking_actions where block_height<=? and bucket_id=any(array(select distinct bucket_id from staking_actions where block_height<=? and candidate=?)) group by bucket_id)) and candidate=?"
rows, err := db.Raw(query, height, height, height, addr, addr).Rows()
if err != nil {
Expand Down

0 comments on commit 7627a7c

Please sign in to comment.