Skip to content

Commit 4c02a85

Browse files
authored
Merge pull request #19 from iotexproject/fix-time-type
fix: MostRecentTPS db query type
2 parents fa9bb6e + 055e74a commit 4c02a85

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

apiservice/chain_service.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package apiservice
33
import (
44
"context"
55
"math/big"
6+
"time"
67

78
"github.com/iotexproject/iotex-analyser-api/api"
89
"github.com/iotexproject/iotex-analyser-api/common"
@@ -107,16 +108,16 @@ func (s *ChainService) MostRecentTPS(ctx context.Context, req *api.MostRecentTPS
107108
db := db.DB()
108109
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<=?"
109110
var result struct {
110-
StartTime uint64
111-
EndTime uint64
111+
StartTime time.Time
112+
EndTime time.Time
112113
NumActions uint64
113114
}
114115
err = db.Raw(query, start, end, start, end).Scan(&result).Error
115116
if err != nil {
116117
return nil, err
117118
}
118119

119-
resp.MostRecentTPS = float64(result.NumActions) / float64(result.EndTime-result.StartTime)
120+
resp.MostRecentTPS = float64(result.NumActions) / float64(result.EndTime.Unix()-result.StartTime.Unix())
120121
return resp, nil
121122
}
122123

0 commit comments

Comments
 (0)