bring in khatru and eventstore.

This commit is contained in:
fiatjaf
2025-04-15 08:49:28 -03:00
parent 8466a9757b
commit 76032dc089
170 changed files with 15018 additions and 42 deletions

View File

@@ -0,0 +1,34 @@
package count
import (
"context"
"github.com/fiatjaf/eventstore"
"github.com/nbd-wtf/go-nostr"
)
type Wrapper struct {
eventstore.Store
}
var _ eventstore.Store = (*Wrapper)(nil)
func (w Wrapper) CountEvents(ctx context.Context, filter nostr.Filter) (int64, error) {
if counter, ok := w.Store.(eventstore.Counter); ok {
return counter.CountEvents(ctx, filter)
}
ch, err := w.Store.QueryEvents(ctx, filter)
if err != nil {
return 0, err
}
if ch == nil {
return 0, nil
}
var count int64
for range ch {
count++
}
return count, nil
}