Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Reverse Ordering Broken Upstream #5

Open
thombruce opened this issue Feb 2, 2021 · 1 comment
Open

Reverse Ordering Broken Upstream #5

thombruce opened this issue Feb 2, 2021 · 1 comment

Comments

@thombruce
Copy link
Owner

thombruce commented Feb 2, 2021

Reverse ordering with RAD currently doesn't work: amark/gun#1011

We currently have a function that aims to retrieve documents in reverse order. Current behaviour is no different than forward order; the '-' key value does not modify the behaviour as expected.

user.get('timestamps')
  .get({ '.': { '<': new Date().getTime(), '-': true }, '%': 100000 })
  .map()
  .get('modifiedAt')
  .map()
  .once(async (document) => {
    // do something with document
  })

How does this affect us? Pagination cannot be used, and retrieval of data by time cannot be depended upon. The only present alternative I'm aware of is to fall back on relative ordering, such as in the basketball example: https://gun.eco/explainers/basketball/basketball.html This however does not guarantee properly sequenced data if we implement pagination.

Another alternative is to query in ranges, like so:

const currentTime = new Date().getTime()
const oneDayAgo = currentTime - 86400000
user.get('timestamps')
  .get({ '.': { '<': currentTime, '>': currentTime - 86400000 }, '%': 100000 })

And we could iterate backwards through paired time values, saving the previous '>' value in memory for Nth iteration.

NOTE: This is how pagination is roughly supposed to work anyway, albeit with a substitute '<' value instead based on the last retrieved index.

To ensure retrieval of all documents, however, we would have to iterate forwards through '>' time values based on previously retrieved keys, THEN when no more are returned decrease both values to the next block of time and repeat that process.

It would work... but let us hope that upstream is fixed before we've need to implement that. 😅

@thombruce
Copy link
Owner Author

thombruce commented Feb 3, 2021

There's an open PR that claims to fix the issue (working on Iris in prod, even?): amark/gun#1021

Spec fails: https://travis-ci.org/github/amark/gun/builds/741186107

Failing spec: https://github.com/amark/gun/pull/1021/files#diff-f080221284314b90c0e57de2157e08de8697bbe904e3f88b5e72fda9b49e2df8

I... have no idea why that's failing. But that's worth remaining aware of.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant