mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-08-31 00:02:20 +02:00
use our own dataloader and simplify batch replaceable requests, removing bugs.
This commit is contained in:
@@ -2,7 +2,6 @@ package sdk
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
@@ -20,39 +19,3 @@ func appendUnique[I comparable](arr []I, item ...I) []I {
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
// doThisNotMoreThanOnceAnHour checks if an operation with the given key
|
||||
// has been performed in the last hour. If not, it returns true and records
|
||||
// the operation to prevent it from running again within the hour.
|
||||
func doThisNotMoreThanOnceAnHour(key string) (doItNow bool) {
|
||||
_dtnmtoahLock.Lock()
|
||||
defer _dtnmtoahLock.Unlock()
|
||||
|
||||
if _dtnmtoah == nil {
|
||||
// this runs only once for the lifetime of this library and
|
||||
// starts a long-running process of checking for expired items
|
||||
// and deleting them from this map every 10 minutes.
|
||||
_dtnmtoah = make(map[string]time.Time)
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(time.Minute * 10)
|
||||
_dtnmtoahLock.Lock()
|
||||
now := time.Now()
|
||||
for k, v := range _dtnmtoah {
|
||||
if v.Before(now) {
|
||||
delete(_dtnmtoah, k)
|
||||
}
|
||||
}
|
||||
_dtnmtoahLock.Unlock()
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
_, hasBeenPerformedInTheLastHour := _dtnmtoah[key]
|
||||
if hasBeenPerformedInTheLastHour {
|
||||
return false
|
||||
}
|
||||
|
||||
_dtnmtoah[key] = time.Now()
|
||||
return true
|
||||
}
|
||||
|
Reference in New Issue
Block a user