mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-28 07:35:56 +00:00
deploy: 5f0e6201ed0fdc28a22b94244cebfcef03c75200
This commit is contained in:
parent
e81223a97c
commit
2373b7c927
@ -1 +1 @@
|
||||
1617937760
|
||||
1617962661
|
@ -126,7 +126,7 @@ procSuite "pagination":
|
||||
pagingInfo = PagingInfo(pageSize: MaxPageSize+1, cursor: msgList[3].index, direction: PagingDirection.FORWARD)
|
||||
(data, newPagingInfo) = paginateWithIndex(msgList, pagingInfo)
|
||||
check:
|
||||
data.len <= MaxPageSize
|
||||
uint64(data.len) <= MaxPageSize
|
||||
newPagingInfo.direction == pagingInfo.direction
|
||||
newPagingInfo.pageSize <= MaxPageSize
|
||||
|
||||
@ -194,13 +194,14 @@ procSuite "pagination":
|
||||
pagingInfo = PagingInfo(pageSize: MaxPageSize+1, cursor: msgList[3].index, direction: PagingDirection.BACKWARD)
|
||||
(data, newPagingInfo) = paginateWithIndex(msgList, pagingInfo)
|
||||
check:
|
||||
data.len <= MaxPageSize
|
||||
uint64(data.len) <= MaxPageSize
|
||||
newPagingInfo.direction == pagingInfo.direction
|
||||
newPagingInfo.pageSize <= MaxPageSize
|
||||
|
||||
# test for a cursor pointing to the begining of the message list
|
||||
pagingInfo = PagingInfo(pageSize: 5, cursor: msgList[0].index, direction: PagingDirection.BACKWARD)
|
||||
(data, newPagingInfo) = paginateWithIndex(msgList, pagingInfo)
|
||||
|
||||
check:
|
||||
data.len == 0
|
||||
newPagingInfo.cursor == msgList[0].index
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# libtool - Provide generalized library-building support services.
|
||||
# Generated automatically by config.status (libbacktrace) version-unused
|
||||
# Libtool was configured on host fv-az278-724:
|
||||
# Libtool was configured on host fv-az190-262:
|
||||
# NOTE: Changes made to this file will be lost: look at ltmain.sh.
|
||||
#
|
||||
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
|
||||
|
@ -96,7 +96,7 @@ proc init*(T: type PagingInfo, buffer: seq[byte]): ProtoResult[T] =
|
||||
var pagingInfo = PagingInfo()
|
||||
let pb = initProtoBuffer(buffer)
|
||||
|
||||
var pageSize: uint32
|
||||
var pageSize: uint64
|
||||
discard ? pb.getField(1, pageSize)
|
||||
pagingInfo.pageSize = pageSize
|
||||
|
||||
@ -227,7 +227,7 @@ proc paginateWithIndex*(list: seq[IndexedWakuMessage], pinfo: PagingInfo): (seq[
|
||||
pageSize = pinfo.pageSize
|
||||
dir = pinfo.direction
|
||||
|
||||
if pageSize == 0: # pageSize being zero indicates that no pagination is required
|
||||
if pageSize == uint64(0): # pageSize being zero indicates that no pagination is required
|
||||
return (list, pinfo)
|
||||
|
||||
if list.len == 0: # no pagination is needed for an empty list
|
||||
@ -236,45 +236,47 @@ proc paginateWithIndex*(list: seq[IndexedWakuMessage], pinfo: PagingInfo): (seq[
|
||||
var msgList = list # makes a copy of the list
|
||||
# sorts msgList based on the custom comparison proc indexedWakuMessageComparison
|
||||
msgList.sort(indexedWakuMessageComparison)
|
||||
|
||||
|
||||
var initQuery = false
|
||||
if cursor == Index():
|
||||
initQuery = true # an empty cursor means it is an intial query
|
||||
initQuery = true # an empty cursor means it is an initial query
|
||||
case dir
|
||||
of PagingDirection.FORWARD:
|
||||
cursor = list[0].index # perform paging from the begining of the list
|
||||
of PagingDirection.BACKWARD:
|
||||
cursor = list[list.len - 1].index # perform paging from the end of the list
|
||||
var foundIndexOption = msgList.findIndex(cursor)
|
||||
# echo "foundIndexOption", foundIndexOption.get()
|
||||
if foundIndexOption.isNone: # the cursor is not valid
|
||||
return (@[], PagingInfo(pageSize: 0, cursor:pinfo.cursor, direction: pinfo.direction))
|
||||
var foundIndex = foundIndexOption.get()
|
||||
var retrievedPageSize, s, e: int
|
||||
var foundIndex = uint64(foundIndexOption.get())
|
||||
var retrievedPageSize, s, e: uint64
|
||||
var newCursor: Index # to be returned as part of the new paging info
|
||||
case dir
|
||||
of PagingDirection.FORWARD: # forward pagination
|
||||
let remainingMessages= msgList.len - foundIndex - 1
|
||||
let remainingMessages= uint64(msgList.len) - uint64(foundIndex) - 1
|
||||
# the number of queried messages cannot exceed the MaxPageSize and the total remaining messages i.e., msgList.len-foundIndex
|
||||
retrievedPageSize = min(int(pageSize), MaxPageSize).min(remainingMessages)
|
||||
retrievedPageSize = min(uint64(pageSize), MaxPageSize).min(remainingMessages)
|
||||
if initQuery : foundIndex = foundIndex - 1
|
||||
s = foundIndex + 1 # non inclusive
|
||||
e = foundIndex + retrievedPageSize
|
||||
newCursor = msgList[e].index # the new cursor points to the end of the page
|
||||
of PagingDirection.BACKWARD: # backward pagination
|
||||
let remainingMessages=foundIndex
|
||||
let remainingMessages = foundIndex
|
||||
# the number of queried messages cannot exceed the MaxPageSize and the total remaining messages i.e., foundIndex-0
|
||||
retrievedPageSize = min(int(pageSize), MaxPageSize).min(remainingMessages)
|
||||
retrievedPageSize = min(uint64(pageSize), MaxPageSize).min(remainingMessages)
|
||||
if initQuery : foundIndex = foundIndex + 1
|
||||
s = foundIndex - retrievedPageSize
|
||||
e = foundIndex - 1
|
||||
newCursor = msgList[s].index # the new cursor points to the begining of the page
|
||||
|
||||
if (retrievedPageSize == 0):
|
||||
return (@[], PagingInfo(pageSize: 0, cursor:pinfo.cursor, direction: pinfo.direction))
|
||||
|
||||
# retrieve the messages
|
||||
for i in s..e:
|
||||
result[0].add(msgList[i])
|
||||
|
||||
result[1] = PagingInfo(pageSize : uint64(retrievedPageSize), cursor : newCursor, direction : pinfo.direction)
|
||||
|
||||
result[1] = PagingInfo(pageSize : retrievedPageSize, cursor : newCursor, direction : pinfo.direction)
|
||||
|
||||
proc paginateWithoutIndex(list: seq[IndexedWakuMessage], pinfo: PagingInfo): (seq[WakuMessage], PagingInfo) =
|
||||
## takes list, and perfomrs paging based on pinfo
|
||||
|
@ -14,7 +14,7 @@ export waku_message
|
||||
export pagination
|
||||
|
||||
# Constants required for pagination -------------------------------------------
|
||||
const MaxPageSize* = 100 # Maximum number of waku messages in each page
|
||||
const MaxPageSize* = uint64(100) # Maximum number of waku messages in each page
|
||||
|
||||
type
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user