mirror of https://github.com/waku-org/nwaku.git
Handling initial paging requests over message history of size one (#479)
* handles initial paging query for history of size one * adds two more tests to fetch the entire history in the initial paging request * increases the pageSize
This commit is contained in:
parent
38b7a257c5
commit
286482ea32
|
@ -103,6 +103,16 @@ procSuite "pagination":
|
||||||
newPagingInfo.direction == pagingInfo.direction
|
newPagingInfo.direction == pagingInfo.direction
|
||||||
newPagingInfo.pageSize == 2
|
newPagingInfo.pageSize == 2
|
||||||
|
|
||||||
|
# test for an initial pagination request with an empty cursor to fetch the entire history
|
||||||
|
pagingInfo = PagingInfo(pageSize: 13, direction: PagingDirection.FORWARD)
|
||||||
|
(data, newPagingInfo) = paginateWithIndex(msgList, pagingInfo)
|
||||||
|
check:
|
||||||
|
data.len == 10
|
||||||
|
data == msgList[0..9]
|
||||||
|
newPagingInfo.cursor == msgList[9].index
|
||||||
|
newPagingInfo.direction == pagingInfo.direction
|
||||||
|
newPagingInfo.pageSize == 10
|
||||||
|
|
||||||
# test for an empty msgList
|
# test for an empty msgList
|
||||||
pagingInfo = PagingInfo(pageSize: 2, direction: PagingDirection.FORWARD)
|
pagingInfo = PagingInfo(pageSize: 2, direction: PagingDirection.FORWARD)
|
||||||
(data, newPagingInfo) = paginateWithIndex(@[], pagingInfo)
|
(data, newPagingInfo) = paginateWithIndex(@[], pagingInfo)
|
||||||
|
@ -148,6 +158,26 @@ procSuite "pagination":
|
||||||
newPagingInfo.direction == pagingInfo.direction
|
newPagingInfo.direction == pagingInfo.direction
|
||||||
newPagingInfo.pageSize == 0
|
newPagingInfo.pageSize == 0
|
||||||
|
|
||||||
|
# test initial paging query over a message list with one message
|
||||||
|
var singleItemMsgList = msgList[0..0]
|
||||||
|
pagingInfo = PagingInfo(pageSize: 10, direction: PagingDirection.FORWARD)
|
||||||
|
(data, newPagingInfo) = paginateWithIndex(singleItemMsgList, pagingInfo)
|
||||||
|
check:
|
||||||
|
data.len == 1
|
||||||
|
newPagingInfo.cursor == msgList[0].index
|
||||||
|
newPagingInfo.direction == pagingInfo.direction
|
||||||
|
newPagingInfo.pageSize == 1
|
||||||
|
|
||||||
|
# test pagination over a message list with one message
|
||||||
|
singleItemMsgList = msgList[0..0]
|
||||||
|
pagingInfo = PagingInfo(pageSize: 10, cursor: msgList[0].index, direction: PagingDirection.FORWARD)
|
||||||
|
(data, newPagingInfo) = paginateWithIndex(singleItemMsgList, pagingInfo)
|
||||||
|
check:
|
||||||
|
data.len == 0
|
||||||
|
newPagingInfo.cursor == msgList[0].index
|
||||||
|
newPagingInfo.direction == pagingInfo.direction
|
||||||
|
newPagingInfo.pageSize == 0
|
||||||
|
|
||||||
test "Backward pagination test":
|
test "Backward pagination test":
|
||||||
var
|
var
|
||||||
msgList = createSampleList(10)
|
msgList = createSampleList(10)
|
||||||
|
@ -180,6 +210,16 @@ procSuite "pagination":
|
||||||
newPagingInfo.direction == pagingInfo.direction
|
newPagingInfo.direction == pagingInfo.direction
|
||||||
newPagingInfo.pageSize == 2
|
newPagingInfo.pageSize == 2
|
||||||
|
|
||||||
|
# test for an initial pagination request with an empty cursor to fetch the entire history
|
||||||
|
pagingInfo = PagingInfo(pageSize: 13, direction: PagingDirection.BACKWARD)
|
||||||
|
(data, newPagingInfo) = paginateWithIndex(msgList, pagingInfo)
|
||||||
|
check:
|
||||||
|
data.len == 10
|
||||||
|
data == msgList[0..9]
|
||||||
|
newPagingInfo.cursor == msgList[0].index
|
||||||
|
newPagingInfo.direction == pagingInfo.direction
|
||||||
|
newPagingInfo.pageSize == 10
|
||||||
|
|
||||||
|
|
||||||
# test for a page size larger than the remaining messages
|
# test for a page size larger than the remaining messages
|
||||||
pagingInfo = PagingInfo(pageSize: 5, cursor: msgList[3].index, direction: PagingDirection.BACKWARD)
|
pagingInfo = PagingInfo(pageSize: 5, cursor: msgList[3].index, direction: PagingDirection.BACKWARD)
|
||||||
|
@ -217,6 +257,26 @@ procSuite "pagination":
|
||||||
newPagingInfo.direction == pagingInfo.direction
|
newPagingInfo.direction == pagingInfo.direction
|
||||||
newPagingInfo.pageSize == 0
|
newPagingInfo.pageSize == 0
|
||||||
|
|
||||||
|
# test initial paging query over a message list with one message
|
||||||
|
var singleItemMsgList = msgList[0..0]
|
||||||
|
pagingInfo = PagingInfo(pageSize: 10, direction: PagingDirection.BACKWARD)
|
||||||
|
(data, newPagingInfo) = paginateWithIndex(singleItemMsgList, pagingInfo)
|
||||||
|
check:
|
||||||
|
data.len == 1
|
||||||
|
newPagingInfo.cursor == msgList[0].index
|
||||||
|
newPagingInfo.direction == pagingInfo.direction
|
||||||
|
newPagingInfo.pageSize == 1
|
||||||
|
|
||||||
|
# test paging query over a message list with one message
|
||||||
|
singleItemMsgList = msgList[0..0]
|
||||||
|
pagingInfo = PagingInfo(pageSize: 10, cursor: msgList[0].index, direction: PagingDirection.BACKWARD)
|
||||||
|
(data, newPagingInfo) = paginateWithIndex(singleItemMsgList, pagingInfo)
|
||||||
|
check:
|
||||||
|
data.len == 0
|
||||||
|
newPagingInfo.cursor == msgList[0].index
|
||||||
|
newPagingInfo.direction == pagingInfo.direction
|
||||||
|
newPagingInfo.pageSize == 0
|
||||||
|
|
||||||
suite "time-window history query":
|
suite "time-window history query":
|
||||||
test "Encode/Decode waku message with timestamp":
|
test "Encode/Decode waku message with timestamp":
|
||||||
# test encoding and decoding of the timestamp field of a WakuMessage
|
# test encoding and decoding of the timestamp field of a WakuMessage
|
||||||
|
|
|
@ -254,7 +254,9 @@ proc paginateWithIndex*(list: seq[IndexedWakuMessage], pinfo: PagingInfo): (seq[
|
||||||
var newCursor: Index # to be returned as part of the new paging info
|
var newCursor: Index # to be returned as part of the new paging info
|
||||||
case dir
|
case dir
|
||||||
of PagingDirection.FORWARD: # forward pagination
|
of PagingDirection.FORWARD: # forward pagination
|
||||||
let remainingMessages= uint64(msgList.len) - uint64(foundIndex) - 1
|
# the message that is pointed by the cursor is excluded for the retrieved list, this is because this message has already been retrieved by the querier in its prior request
|
||||||
|
var remainingMessages= uint64(msgList.len) - uint64(foundIndex) - 1
|
||||||
|
if initQuery: remainingMessages = remainingMessages + 1
|
||||||
# the number of queried messages cannot exceed the MaxPageSize and the total remaining messages i.e., msgList.len-foundIndex
|
# the number of queried messages cannot exceed the MaxPageSize and the total remaining messages i.e., msgList.len-foundIndex
|
||||||
retrievedPageSize = min(uint64(pageSize), MaxPageSize).min(remainingMessages)
|
retrievedPageSize = min(uint64(pageSize), MaxPageSize).min(remainingMessages)
|
||||||
if initQuery : foundIndex = foundIndex - 1
|
if initQuery : foundIndex = foundIndex - 1
|
||||||
|
@ -262,7 +264,8 @@ proc paginateWithIndex*(list: seq[IndexedWakuMessage], pinfo: PagingInfo): (seq[
|
||||||
e = foundIndex + retrievedPageSize
|
e = foundIndex + retrievedPageSize
|
||||||
newCursor = msgList[e].index # the new cursor points to the end of the page
|
newCursor = msgList[e].index # the new cursor points to the end of the page
|
||||||
of PagingDirection.BACKWARD: # backward pagination
|
of PagingDirection.BACKWARD: # backward pagination
|
||||||
let remainingMessages = foundIndex
|
var remainingMessages = foundIndex
|
||||||
|
if initQuery: remainingMessages = remainingMessages + 1
|
||||||
# the number of queried messages cannot exceed the MaxPageSize and the total remaining messages i.e., foundIndex-0
|
# the number of queried messages cannot exceed the MaxPageSize and the total remaining messages i.e., foundIndex-0
|
||||||
retrievedPageSize = min(uint64(pageSize), MaxPageSize).min(remainingMessages)
|
retrievedPageSize = min(uint64(pageSize), MaxPageSize).min(remainingMessages)
|
||||||
if initQuery : foundIndex = foundIndex + 1
|
if initQuery : foundIndex = foundIndex + 1
|
||||||
|
|
Loading…
Reference in New Issue