forked from coracle/nostrlib
eventstore/mmm: use sync.Pool for tempResults.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"slices"
|
"slices"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
"fiatjaf.com/nostr/eventstore/codec/betterbinary"
|
"fiatjaf.com/nostr/eventstore/codec/betterbinary"
|
||||||
@@ -14,6 +15,12 @@ import (
|
|||||||
"github.com/PowerDNS/lmdb-go/lmdb"
|
"github.com/PowerDNS/lmdb-go/lmdb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var tempResultsPool = sync.Pool{
|
||||||
|
New: func() any {
|
||||||
|
return make([]nostr.Event, 0, 64)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// GetByID returns the event -- if found in this mmm -- and all the IndexingLayers it belongs to.
|
// GetByID returns the event -- if found in this mmm -- and all the IndexingLayers it belongs to.
|
||||||
func (b *MultiMmapManager) GetByID(id nostr.ID) (*nostr.Event, IndexingLayers) {
|
func (b *MultiMmapManager) GetByID(id nostr.ID) (*nostr.Event, IndexingLayers) {
|
||||||
var event *nostr.Event
|
var event *nostr.Event
|
||||||
@@ -140,7 +147,8 @@ func (il *IndexingLayer) query(txn *lmdb.Txn, filter nostr.Filter, limit int, yi
|
|||||||
|
|
||||||
numberOfIteratorsToPullOnEachRound := max(1, int(math.Ceil(float64(len(iterators))/float64(12))))
|
numberOfIteratorsToPullOnEachRound := max(1, int(math.Ceil(float64(len(iterators))/float64(12))))
|
||||||
totalEventsEmitted := 0
|
totalEventsEmitted := 0
|
||||||
tempResults := make([]nostr.Event, 0, batchSizePerQuery*2)
|
tempResults := tempResultsPool.Get().([]nostr.Event)
|
||||||
|
defer tempResultsPool.Put(tempResults[:0])
|
||||||
|
|
||||||
for len(iterators) > 0 {
|
for len(iterators) > 0 {
|
||||||
// reset stuff
|
// reset stuff
|
||||||
|
|||||||
Reference in New Issue
Block a user