From f0ed5e32d570c52b9883c0d87d201fba0bdab1d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rich=CE=9Brd?= Date: Wed, 6 Dec 2023 09:02:05 -0400 Subject: [PATCH] fix(store): set pagesize behavior match nwaku (#944) --- cmd/waku/server/rest/store.go | 5 ++++- waku/v2/protocol/store/waku_store_client.go | 6 ++++-- waku/v2/protocol/store/waku_store_common.go | 4 +++- waku/v2/protocol/store/waku_store_protocol.go | 4 +++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cmd/waku/server/rest/store.go b/cmd/waku/server/rest/store.go index 19f3e048..8e8ac87b 100644 --- a/cmd/waku/server/rest/store.go +++ b/cmd/waku/server/rest/store.go @@ -132,7 +132,7 @@ func getStoreParams(r *http.Request) (*store.Query, []store.HistoryRequestOption ascendingStr := r.URL.Query().Get("ascending") if ascendingStr != "" || pageSizeStr != "" { ascending := true - pageSize := uint64(store.MaxPageSize) + pageSize := uint64(store.DefaultPageSize) if ascendingStr != "" { ascending, err = strconv.ParseBool(ascendingStr) if err != nil { @@ -145,6 +145,9 @@ func getStoreParams(r *http.Request) (*store.Query, []store.HistoryRequestOption if err != nil { return nil, nil, err } + if pageSize > store.MaxPageSize { + pageSize = store.MaxPageSize + } } options = append(options, store.WithPaging(ascending, pageSize)) diff --git a/waku/v2/protocol/store/waku_store_client.go b/waku/v2/protocol/store/waku_store_client.go index 482be4ac..9e568797 100644 --- a/waku/v2/protocol/store/waku_store_client.go +++ b/waku/v2/protocol/store/waku_store_client.go @@ -195,7 +195,7 @@ func DefaultOptions() []HistoryRequestOption { return []HistoryRequestOption{ WithAutomaticRequestID(), WithAutomaticPeerSelection(), - WithPaging(true, MaxPageSize), + WithPaging(true, DefaultPageSize), } } @@ -359,7 +359,9 @@ func (store *WakuStore) Query(ctx context.Context, query Query, opts ...HistoryR } pageSize := params.pageSize - if pageSize == 0 || pageSize > uint64(MaxPageSize) { + if pageSize == 0 { + pageSize = DefaultPageSize + } else if pageSize > uint64(MaxPageSize) { pageSize = MaxPageSize } historyRequest.Query.PagingInfo.PageSize = pageSize diff --git a/waku/v2/protocol/store/waku_store_common.go b/waku/v2/protocol/store/waku_store_common.go index 1781d3e3..82e369cf 100644 --- a/waku/v2/protocol/store/waku_store_common.go +++ b/waku/v2/protocol/store/waku_store_common.go @@ -19,7 +19,9 @@ const StoreID_v20beta4 = libp2pProtocol.ID("/vac/waku/store/2.0.0-beta4") const StoreENRField = uint8(1 << 1) // MaxPageSize is the maximum number of waku messages to return per page -const MaxPageSize = 20 +const MaxPageSize = 100 + +const DefaultPageSize = 20 var ( diff --git a/waku/v2/protocol/store/waku_store_protocol.go b/waku/v2/protocol/store/waku_store_protocol.go index b45b57e4..76e3983f 100644 --- a/waku/v2/protocol/store/waku_store_protocol.go +++ b/waku/v2/protocol/store/waku_store_protocol.go @@ -30,7 +30,9 @@ func findMessages(query *pb.HistoryQuery, msgProvider MessageProvider) ([]*wpb.W } } - if query.PagingInfo.PageSize == 0 || query.PagingInfo.PageSize > uint64(MaxPageSize) { + if query.PagingInfo.PageSize == 0 { + query.PagingInfo.PageSize = DefaultPageSize + } else if query.PagingInfo.PageSize > uint64(MaxPageSize) { query.PagingInfo.PageSize = MaxPageSize }