Optimize API block count
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2023-05-30 11:42:56 +02:00
parent e616cd6d82
commit f348588b37
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
2 changed files with 6 additions and 2 deletions

View file

@ -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

View file

@ -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) {