eventstore: more consistent ErrDupEvent firing.
This commit is contained in:
@@ -4,6 +4,7 @@ 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"
|
||||||
)
|
)
|
||||||
@@ -32,6 +33,10 @@ func (b *LMDBBackend) SaveEvent(evt nostr.Event) error {
|
|||||||
return b.save(txn, evt)
|
return b.save(txn, evt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
return eventstore.ErrDupEvent
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"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"
|
||||||
)
|
)
|
||||||
@@ -80,7 +81,7 @@ func (b *MultiMmapManager) storeOn(
|
|||||||
ilid := binary.BigEndian.Uint16(val[s : s+2])
|
ilid := binary.BigEndian.Uint16(val[s : s+2])
|
||||||
if il.id == ilid {
|
if il.id == ilid {
|
||||||
// already on the specified layer, we can end here
|
// already on the specified layer, we can end here
|
||||||
return false, nil
|
return false, eventstore.ErrDupEvent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if !lmdb.IsNotFound(err) {
|
} else if !lmdb.IsNotFound(err) {
|
||||||
|
|||||||
@@ -33,12 +33,11 @@ func (w StorePublisher) Publish(ctx context.Context, evt nostr.Event) error {
|
|||||||
// regular events are just saved directly
|
// regular events are just saved directly
|
||||||
if err := w.SaveEvent(evt); err != nil && err != eventstore.ErrDupEvent {
|
if err := w.SaveEvent(evt); err != nil && err != eventstore.ErrDupEvent {
|
||||||
return fmt.Errorf("failed to save: %w", err)
|
return fmt.Errorf("failed to save: %w", err)
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// others are replaced
|
// others are replaced
|
||||||
w.Store.ReplaceEvent(evt)
|
return w.Store.ReplaceEvent(evt)
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package policies
|
package wrappers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
Reference in New Issue
Block a user