helium-js icon indicating copy to clipboard operation
helium-js copied to clipboard

*hasMore* attribute of list is always set to true even when list is empty.

Open MohdImran001 opened this issue 4 years ago • 3 comments

While working on the issue https://github.com/helium/explorer/issues/216, I found out that hasMore attribute of the list is always set to true even when the list is empty and also when there is no more data to show.

helium_resource_list

To check the bug, we only need to add console.log(this.list) statement as shown below in ActivityList.js component in Explorer.

load_more

This is the code snippet that is used create a list.

make_list

Hey @danielcolinjames and @allenan. I would love to know your suggestions on this issue.

MohdImran001 avatar Feb 24 '21 16:02 MohdImran001

left some comments regarding this on https://github.com/helium/explorer/pull/257. But the gist is that helium-js exposes 2 different pagination strategies. The first is a traditional page-based system that wraps the cursor system from the API. The nextPage and hasMore functions and the data property are part of this system. The second pagination system is an async iterator approach which uses take to abstract the concept of pages. You can continue to "take" from the resource and it will perform any page fetches required to satisfy that amount under the hood. When take stops returning items, you've exhausted that resource. Hopefully that helps clear things up

allenan avatar Mar 06 '21 19:03 allenan

Hey @allenan, Thanks for the explanation. This has cleared my doubt. Is it possible to remove hasMore attribute from the response when a take function is called because even when the list is empty initially the hasMore attribute is set to true and is creating confusion between the two pagination methods.

MohdImran001 avatar Mar 07 '21 03:03 MohdImran001

I seem to have this problem for traditional page-based system:

const { activity } = new Client(Network.production).accounts.get(account)
const txs: AnyTransaction[] = []
let page = await activity.list()
page.data.forEach(anyTx => txs.push(anyTx))

// this fails with 429 (too many requests); page.hasMore seems to be always true,
// even if there are 2 txs, like for 13eCVbi4tTofg38hT5rUFufKHmp1v9X4WDLtBUx2aytaFjRGqf4 (random address from explorer)
// for which the loop is expected to not even start
while(page.hasMore) {
    page = await page.nextPage()
    page.data.forEach(anyTx => txs.push(anyTx))
}

YakovL avatar Feb 20 '22 13:02 YakovL