Skip to content

Commit

Permalink
fix(store): query time comparison and max rows per page
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Oct 12, 2023
1 parent 5dcae1d commit 5253173
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion waku/persistence/db_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ func (k *DBKey) Bytes() []byte {

// NewDBKey creates a new DBKey with the given values.
func NewDBKey(senderTimestamp uint64, receiverTimestamp uint64, pubsubTopic string, digest []byte) *DBKey {
pubSubHash := hash.SHA256([]byte(pubsubTopic))
pubSubHash := make([]byte, PubsubTopicLength)
if pubsubTopic != "" {
pubSubHash = hash.SHA256([]byte(pubsubTopic))
}

var k DBKey
k.raw = make([]byte, DBKeyLength)
Expand Down
4 changes: 2 additions & 2 deletions waku/persistence/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (d *DBStore) handleQueryCursor(query *pb.HistoryQuery, paramCnt *int, condi
handleTimeParam := func(time int64, op string) {
*paramCnt++
conditions = append(conditions, fmt.Sprintf("id %s $%d", op, *paramCnt))
timeDBKey := NewDBKey(uint64(time), uint64(time), "", []byte{})
timeDBKey := NewDBKey(uint64(time), 0, "", []byte{})
parameters = append(parameters, timeDBKey.Bytes())
}

Expand All @@ -358,7 +358,7 @@ func (d *DBStore) handleQueryCursor(query *pb.HistoryQuery, paramCnt *int, condi

if query.EndTime != 0 {
if !usesCursor || query.PagingInfo.Direction == pb.PagingInfo_FORWARD {
handleTimeParam(query.EndTime, "<=")
handleTimeParam(query.EndTime+1, "<")
}
}
return conditions, parameters, nil
Expand Down
4 changes: 2 additions & 2 deletions waku/persistence/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ func TestQuery(t *testing.T) {
{ContentTopic: "test3"},
},
PagingInfo: &pb.PagingInfo{PageSize: 10},
StartTime: insertTime.Add(-41 * time.Second).UnixNano(),
EndTime: insertTime.Add(-21 * time.Second).UnixNano(),
StartTime: insertTime.Add(-40 * time.Second).UnixNano(),
EndTime: insertTime.Add(-20 * time.Second).UnixNano(),
})
require.NoError(t, err)
require.Len(t, msgs, 2)
Expand Down
2 changes: 1 addition & 1 deletion waku/v2/protocol/store/waku_store_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
const StoreID_v20beta4 = libp2pProtocol.ID("/vac/waku/store/2.0.0-beta4")

// MaxPageSize is the maximum number of waku messages to return per page
const MaxPageSize = 100
const MaxPageSize = 20

// MaxContentFilters is the maximum number of allowed content filters in a query
const MaxContentFilters = 10
Expand Down

0 comments on commit 5253173

Please sign in to comment.