eventstore: fix lmdb storing the same event a million times.
This commit is contained in:
@@ -31,7 +31,7 @@ func (b *BoltBackend) SaveEvent(evt nostr.Event) error {
|
|||||||
// check if we already have this id
|
// check if we already have this id
|
||||||
bin := rawBucket.Get(evt.ID[16:24])
|
bin := rawBucket.Get(evt.ID[16:24])
|
||||||
if bin != nil {
|
if bin != nil {
|
||||||
// we should get nil, otherwise end here
|
// we should get nil, otherwise we already have it so end here
|
||||||
return eventstore.ErrDupEvent
|
return eventstore.ErrDupEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
"fiatjaf.com/nostr/eventstore"
|
|
||||||
"fiatjaf.com/nostr/eventstore/codec/betterbinary"
|
"fiatjaf.com/nostr/eventstore/codec/betterbinary"
|
||||||
"github.com/PowerDNS/lmdb-go/lmdb"
|
"github.com/PowerDNS/lmdb-go/lmdb"
|
||||||
)
|
)
|
||||||
@@ -28,12 +27,12 @@ func (b *LMDBBackend) SaveEvent(evt nostr.Event) error {
|
|||||||
|
|
||||||
// check if we already have this id
|
// check if we already have this id
|
||||||
_, err := txn.Get(b.indexId, evt.ID[0:8])
|
_, err := txn.Get(b.indexId, evt.ID[0:8])
|
||||||
if operr, ok := err.(*lmdb.OpError); ok && operr.Errno != lmdb.NotFound {
|
if operr, ok := err.(*lmdb.OpError); ok && operr.Errno == lmdb.NotFound {
|
||||||
// we will only proceed if we get a NotFound
|
// we will only proceed if we get a NotFound
|
||||||
return eventstore.ErrDupEvent
|
return b.save(txn, evt)
|
||||||
}
|
}
|
||||||
|
|
||||||
return b.save(txn, evt)
|
return err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user