fix GetTheoreticalLimit() buggy logic.
This commit is contained in:
@@ -32,7 +32,6 @@ func (b *BadgerBackend) QueryEvents(filter nostr.Filter, maxLimit int) iter.Seq[
|
||||
maxLimit = filter.Limit
|
||||
}
|
||||
|
||||
// fmt.Println("limit", limit)
|
||||
b.View(func(txn *badger.Txn) error {
|
||||
results, err := b.query(txn, filter, maxLimit)
|
||||
if err != nil {
|
||||
@@ -161,7 +160,7 @@ func (b *BadgerBackend) query(txn *badger.Txn, filter nostr.Filter, limit int) (
|
||||
}
|
||||
|
||||
if err := item.Value(func(bin []byte) error {
|
||||
// fmt.Println(" event", betterbinary.GetID(bin ), "kind", betterbinary.GetKind(bin ).Num(), "author", betterbinary.GetPubKey(bin ), "ts", betterbinary.GetCreatedAt(bin ), hex.EncodeToString(it.key), it.valIdx)
|
||||
// fmt.Println(" event", betterbinary.GetID(bin), "kind", betterbinary.GetKind(bin).Num(), "author", betterbinary.GetPubKey(bin), "ts", betterbinary.GetCreatedAt(bin))
|
||||
|
||||
// check it against pubkeys without decoding the entire thing
|
||||
if extraFilter != nil && extraFilter.Authors != nil &&
|
||||
|
||||
@@ -157,11 +157,7 @@ func (filter Filter) GetTheoreticalLimit() int {
|
||||
return len(filter.IDs)
|
||||
}
|
||||
|
||||
if filter.Kinds != nil {
|
||||
return math.MaxInt
|
||||
}
|
||||
|
||||
if filter.Authors != nil {
|
||||
if filter.Authors != nil && filter.Kinds != nil {
|
||||
allAreReplaceable := true
|
||||
for _, kind := range filter.Kinds {
|
||||
if !kind.IsReplaceable() {
|
||||
|
||||
@@ -143,6 +143,7 @@ func TestFilterClone(t *testing.T) {
|
||||
func TestTheoreticalLimit(t *testing.T) {
|
||||
require.Equal(t, 6, Filter{IDs: []ID{{'a'}, {'b'}, {'c'}, {'d'}, {'e'}, {'f'}}}.GetTheoreticalLimit())
|
||||
require.Equal(t, 9, Filter{Authors: []PubKey{{'a'}, {'b'}, {'c'}}, Kinds: []Kind{3, 0, 10002}}.GetTheoreticalLimit())
|
||||
require.Equal(t, math.MaxInt, Filter{Authors: []PubKey{{'a'}}}.GetTheoreticalLimit())
|
||||
require.Equal(t, 4, Filter{Authors: []PubKey{{'a'}, {'b'}, {'c'}, {'d'}}, Kinds: []Kind{10050}}.GetTheoreticalLimit())
|
||||
require.Equal(t, math.MaxInt, Filter{Authors: []PubKey{{'a'}, {'b'}, {'c'}, {'d'}}}.GetTheoreticalLimit())
|
||||
require.Equal(t, math.MaxInt, Filter{Kinds: []Kind{3, 0, 10002}}.GetTheoreticalLimit())
|
||||
|
||||
Reference in New Issue
Block a user