make lmdb and badger backends use a binary encoding instead of nson.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package badgern
|
||||
package badger
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nson"
|
||||
nostr_binary "github.com/nbd-wtf/go-nostr/binary"
|
||||
)
|
||||
|
||||
func (b BadgerBackend) CountEvents(ctx context.Context, filter nostr.Filter) (int64, error) {
|
||||
@@ -58,7 +58,7 @@ func (b BadgerBackend) CountEvents(ctx context.Context, filter nostr.Filter) (in
|
||||
} else {
|
||||
err = item.Value(func(val []byte) error {
|
||||
evt := &nostr.Event{}
|
||||
if err := nson.Unmarshal(string(val), evt); err != nil {
|
||||
if err := nostr_binary.Unmarshal(val, evt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package badgern
|
||||
package badger
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nson"
|
||||
nostr_binary "github.com/nbd-wtf/go-nostr/binary"
|
||||
)
|
||||
|
||||
func (b *BadgerBackend) DeleteEvent(ctx context.Context, evt *nostr.Event) error {
|
||||
@@ -43,7 +43,7 @@ func (b *BadgerBackend) DeleteEvent(ctx context.Context, evt *nostr.Event) error
|
||||
|
||||
item.Value(func(val []byte) error {
|
||||
evt := &nostr.Event{}
|
||||
if err := nson.Unmarshal(string(val), evt); err != nil {
|
||||
if err := nostr_binary.Unmarshal(val, evt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package badgern
|
||||
package badger
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
@@ -1,4 +1,4 @@
|
||||
package badgern
|
||||
package badger
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nson"
|
||||
nostr_binary "github.com/nbd-wtf/go-nostr/binary"
|
||||
)
|
||||
|
||||
type query struct {
|
||||
@@ -75,7 +75,7 @@ func (b BadgerBackend) QueryEvents(ctx context.Context, filter nostr.Filter) (ch
|
||||
}
|
||||
err = item.Value(func(val []byte) error {
|
||||
evt := &nostr.Event{}
|
||||
if err := nson.Unmarshal(string(val), evt); err != nil {
|
||||
if err := nostr_binary.Unmarshal(val, evt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
package badgern
|
||||
package badger
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nson"
|
||||
nostr_binary "github.com/nbd-wtf/go-nostr/binary"
|
||||
)
|
||||
|
||||
func (b *BadgerBackend) SaveEvent(ctx context.Context, evt *nostr.Event) error {
|
||||
return b.Update(func(txn *badger.Txn) error {
|
||||
nson, err := nson.Marshal(evt)
|
||||
bin, err := nostr_binary.Marshal(evt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
idx := b.Serial()
|
||||
// raw event store
|
||||
if err := txn.Set(idx, []byte(nson)); err != nil {
|
||||
if err := txn.Set(idx, bin); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package lmdbn
|
||||
package lmdb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/bmatsuo/lmdb-go/lmdb"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nson"
|
||||
nostr_binary "github.com/nbd-wtf/go-nostr/binary"
|
||||
)
|
||||
|
||||
func (b *LMDBBackend) CountEvents(ctx context.Context, filter nostr.Filter) (int64, error) {
|
||||
@@ -67,7 +67,7 @@ func (b *LMDBBackend) CountEvents(ctx context.Context, filter nostr.Filter) (int
|
||||
count++
|
||||
} else {
|
||||
evt := &nostr.Event{}
|
||||
if err := nson.Unmarshal(string(val), evt); err != nil {
|
||||
if err := nostr_binary.Unmarshal(val, evt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package lmdbn
|
||||
package lmdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/bmatsuo/lmdb-go/lmdb"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nson"
|
||||
nostr_binary "github.com/nbd-wtf/go-nostr/binary"
|
||||
)
|
||||
|
||||
func (b *LMDBBackend) DeleteEvent(ctx context.Context, evt *nostr.Event) error {
|
||||
@@ -28,7 +28,7 @@ func (b *LMDBBackend) DeleteEvent(ctx context.Context, evt *nostr.Event) error {
|
||||
}
|
||||
|
||||
evt := &nostr.Event{}
|
||||
if err := nson.Unmarshal(string(val), evt); err != nil {
|
||||
if err := nostr_binary.Unmarshal(val, evt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package lmdbn
|
||||
package lmdb
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
@@ -1,4 +1,4 @@
|
||||
package lmdbn
|
||||
package lmdb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/bmatsuo/lmdb-go/lmdb"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nson"
|
||||
nostr_binary "github.com/nbd-wtf/go-nostr/binary"
|
||||
)
|
||||
|
||||
type query struct {
|
||||
@@ -92,7 +92,7 @@ func (b *LMDBBackend) QueryEvents(ctx context.Context, filter nostr.Filter) (cha
|
||||
}
|
||||
|
||||
evt := &nostr.Event{}
|
||||
if err := nson.Unmarshal(string(val), evt); err != nil {
|
||||
if err := nostr_binary.Unmarshal(val, evt); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package lmdbn
|
||||
package lmdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/bmatsuo/lmdb-go/lmdb"
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/nbd-wtf/go-nostr/nson"
|
||||
nostr_binary "github.com/nbd-wtf/go-nostr/binary"
|
||||
)
|
||||
|
||||
func (b *LMDBBackend) SaveEvent(ctx context.Context, evt *nostr.Event) error {
|
||||
@@ -16,14 +16,14 @@ func (b *LMDBBackend) SaveEvent(ctx context.Context, evt *nostr.Event) error {
|
||||
}
|
||||
|
||||
return b.lmdbEnv.Update(func(txn *lmdb.Txn) error {
|
||||
nson, err := nson.Marshal(evt)
|
||||
bin, err := nostr_binary.Marshal(evt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
idx := b.Serial()
|
||||
// raw event store
|
||||
if err := txn.Put(b.rawEventStore, idx, []byte(nson), 0); err != nil {
|
||||
if err := txn.Put(b.rawEventStore, idx, bin, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user