From f53493961274788898a28f6b41eff05ad1f5ca08 Mon Sep 17 00:00:00 2001 From: WeebDataHoarder <57538841+WeebDataHoarder@users.noreply.github.com> Date: Sat, 27 May 2023 21:52:01 +0200 Subject: [PATCH] Use buffered channels on Index --- index/index.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index/index.go b/index/index.go index e984c0e..969e6bd 100644 --- a/index/index.go +++ b/index/index.go @@ -323,7 +323,7 @@ func (i *Index) PrepareSideBlocksByQueryStatement(where string) (stmt *sql.Stmt, func (i *Index) GetSideBlocksByQuery(where string, params ...any) chan *SideBlock { if stmt, err := i.PrepareSideBlocksByQueryStatement(where); err != nil { - returnChannel := make(chan *SideBlock) + returnChannel := make(chan *SideBlock, 1) close(returnChannel) return returnChannel } else { @@ -332,7 +332,7 @@ func (i *Index) GetSideBlocksByQuery(where string, params ...any) chan *SideBloc } func (i *Index) getSideBlocksByQueryStatement(stmt *sql.Stmt, params ...any) chan *SideBlock { - returnChannel := make(chan *SideBlock) + returnChannel := make(chan *SideBlock, 1) go func() { defer stmt.Close() defer close(returnChannel) @@ -355,7 +355,7 @@ func (i *Index) getSideBlocksByQueryStatement(stmt *sql.Stmt, params ...any) cha } func (i *Index) GetSideBlocksByQueryStatement(stmt *sql.Stmt, params ...any) chan *SideBlock { - returnChannel := make(chan *SideBlock) + returnChannel := make(chan *SideBlock, 1) go func() { defer close(returnChannel) err := i.QueryStatement(stmt, func(row RowScanInterface) (err error) { @@ -431,7 +431,7 @@ func (i *Index) GetFoundBlocks(where string, limit uint64, params ...any) []*Fou func (i *Index) GetMainBlocksByQuery(where string, params ...any) chan *MainBlock { if stmt, err := i.PrepareMainBlocksByQueryStatement(where); err != nil { - returnChannel := make(chan *MainBlock) + returnChannel := make(chan *MainBlock, 1) close(returnChannel) return returnChannel } else { @@ -440,7 +440,7 @@ func (i *Index) GetMainBlocksByQuery(where string, params ...any) chan *MainBloc } func (i *Index) getMainBlocksByQueryStatement(stmt *sql.Stmt, params ...any) chan *MainBlock { - returnChannel := make(chan *MainBlock) + returnChannel := make(chan *MainBlock, 1) go func() { defer stmt.Close() defer close(returnChannel) @@ -463,7 +463,7 @@ func (i *Index) getMainBlocksByQueryStatement(stmt *sql.Stmt, params ...any) cha } func (i *Index) GetMainBlocksByQueryStatement(stmt *sql.Stmt, params ...any) chan *MainBlock { - returnChannel := make(chan *MainBlock) + returnChannel := make(chan *MainBlock, 1) go func() { defer close(returnChannel) err := i.QueryStatement(stmt, func(row RowScanInterface) (err error) { @@ -663,7 +663,7 @@ func (i *Index) InsertOrUpdateMainBlock(b *MainBlock) error { } func (i *Index) GetPayoutsByMinerId(minerId uint64, limit uint64) chan *Payout { - out := make(chan *Payout) + out := make(chan *Payout, 1) go func() { defer close(out) @@ -692,7 +692,7 @@ func (i *Index) GetPayoutsByMinerId(minerId uint64, limit uint64) chan *Payout { } func (i *Index) GetPayoutsBySideBlock(b *SideBlock) chan *Payout { - out := make(chan *Payout) + out := make(chan *Payout, 1) go func() { defer close(out) @@ -762,7 +762,7 @@ func (i *Index) GetMainCoinbaseOutputByGlobalOutputIndex(globalOutputIndex uint6 } func (i *Index) GetMainLikelySweepTransactions(limit uint64) chan *MainLikelySweepTransaction { - out := make(chan *MainLikelySweepTransaction) + out := make(chan *MainLikelySweepTransaction, 1) go func() { defer close(out) @@ -790,7 +790,7 @@ func (i *Index) GetMainLikelySweepTransactions(limit uint64) chan *MainLikelySwe } func (i *Index) GetMainLikelySweepTransactionsByAddress(addr *address.Address, limit uint64) chan *MainLikelySweepTransaction { - out := make(chan *MainLikelySweepTransaction) + out := make(chan *MainLikelySweepTransaction, 1) go func() { defer close(out)