Optimize API block count
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e616cd6d82
commit
f348588b37
|
@ -227,9 +227,9 @@ func main() {
|
|||
minersKnown uint64
|
||||
}
|
||||
|
||||
totalKnown := cacheResult(CacheTotalKnownBlocksAndMiners, time.Second*15, func() any {
|
||||
totalKnown := cacheResult(CacheTotalKnownBlocksAndMiners, time.Minute, func() any {
|
||||
result := &totalKnownResult{}
|
||||
if err := indexDb.Query("SELECT (SELECT COUNT(*) FROM main_blocks WHERE side_template_id IS NOT NULL) as found, (SELECT COUNT(*) FROM miners) as miners;", func(row index.RowScanInterface) error {
|
||||
if err := indexDb.Query("SELECT (SELECT COUNT(*) FROM "+indexDb.GetView("found_main_blocks")+") as found, (SELECT COUNT(*) FROM miners) as miners;", func(row index.RowScanInterface) error {
|
||||
return row.Scan(&result.blocksFound, &result.minersKnown)
|
||||
}); err != nil {
|
||||
return nil
|
||||
|
|
|
@ -373,6 +373,10 @@ type Scannable interface {
|
|||
ScanFromRow(i *Index, row RowScanInterface) error
|
||||
}
|
||||
|
||||
func (i *Index) GetView(k string) string {
|
||||
return i.views[k]
|
||||
}
|
||||
|
||||
func (i *Index) Query(query string, callback func(row RowScanInterface) error, params ...any) error {
|
||||
var parentError error
|
||||
pprof.Do(context.Background(), pprof.Labels("query", query), func(ctx context.Context) {
|
||||
|
|
Loading…
Reference in a new issue