Skip to content

Commit

Permalink
Merge pull request #19 from iotexproject/fix-time-type
Browse files Browse the repository at this point in the history
fix: MostRecentTPS db query type
  • Loading branch information
huangzhiran authored Aug 26, 2024
2 parents fa9bb6e + 055e74a commit 4c02a85
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions apiservice/chain_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package apiservice
import (
"context"
"math/big"
"time"

"github.com/iotexproject/iotex-analyser-api/api"
"github.com/iotexproject/iotex-analyser-api/common"
Expand Down Expand Up @@ -107,16 +108,16 @@ func (s *ChainService) MostRecentTPS(ctx context.Context, req *api.MostRecentTPS
db := db.DB()
query := "select (select timestamp from block where block_height=?) start_time,(select timestamp from block where block_height=?) end_time,sum(num_actions) num_actions from block where block_height>=? and block_height<=?"
var result struct {
StartTime uint64
EndTime uint64
StartTime time.Time
EndTime time.Time
NumActions uint64
}
err = db.Raw(query, start, end, start, end).Scan(&result).Error
if err != nil {
return nil, err
}

resp.MostRecentTPS = float64(result.NumActions) / float64(result.EndTime-result.StartTime)
resp.MostRecentTPS = float64(result.NumActions) / float64(result.EndTime.Unix()-result.StartTime.Unix())
return resp, nil
}

Expand Down

0 comments on commit 4c02a85

Please sign in to comment.