no retry if page count is zero

This commit is contained in:
Daniel Lugo 2020-07-11 16:57:22 -04:00
parent 64c16d88e7
commit 54f223ac99

View file

@ -44,11 +44,13 @@ const getWallPage = async (page, publicKey) => {
) )
} }
if (totalPages === 0) { const empty = {
return {
count: 0, count: 0,
posts: {} posts: {}
} }
if (totalPages === 0) {
return empty
} }
const actualPageIdx = page < 0 ? totalPages + page : page - 1 const actualPageIdx = page < 0 ? totalPages + page : page - 1
@ -57,6 +59,28 @@ const getWallPage = async (page, publicKey) => {
throw new RangeError(`Requested a page out of bounds`) throw new RangeError(`Requested a page out of bounds`)
} }
/**
* @type {number}
*/
// @ts-ignore
const count = await Utils.tryAndWait(
(g, u) => {
const user = publicKey ? g.get(`~${publicKey}`) : u
return user
.get(Key.WALL)
.get(Key.PAGES)
.get(actualPageIdx.toString())
.get(Key.COUNT)
.then()
},
v => typeof v !== 'number'
)
if (count === 0) {
return empty
}
/** /**
* @type {Common.SchemaTypes.WallPage} * @type {Common.SchemaTypes.WallPage}
*/ */