From 54f223ac99ac2e9e81217bd99cc65c7675642491 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 11 Jul 2020 16:57:22 -0400 Subject: [PATCH] no retry if page count is zero --- services/gunDB/contact-api/getters/wall.js | 32 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/services/gunDB/contact-api/getters/wall.js b/services/gunDB/contact-api/getters/wall.js index 83cdb5a7..6a4b2aa5 100644 --- a/services/gunDB/contact-api/getters/wall.js +++ b/services/gunDB/contact-api/getters/wall.js @@ -44,11 +44,13 @@ const getWallPage = async (page, publicKey) => { ) } + const empty = { + count: 0, + posts: {} + } + if (totalPages === 0) { - return { - count: 0, - posts: {} - } + return empty } 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`) } + /** + * @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} */