thinky icon indicating copy to clipboard operation
thinky copied to clipboard

Implement ordered ranges

Open neumino opened this issue 10 years ago • 4 comments

For

Users.orderBy({index: "score"}).limit(10).changes()

We should return an array of 10 documents and maintain it up to date. This is pending some changes on the server: https://github.com/rethinkdb/rethinkdb/issues/3714

If the changes don't make it for 2.0, I'll implement a work around (a bit less efficient than if the feeds return the positions of the changes).

neumino avatar Feb 03 '15 07:02 neumino

That's technically possible now.

The question is how to expose it. Here's what I have in mind

io.on('connection', function(socket){
    Users.orderBy({index: "score"}).limit(10).changes({includeStates: true}).run().then(function(range) {
        socket.broadcast.emit(JSON.stringify(range.toArray()));
        range.each(function(patch) { // equivalent to range.on("change", function(patch) {
            socket.broadcast(patch)
        })
    })
});

A few things to note:

  • toArray is synchronous here
  • patch would be a JSON patch as described here: http://jsonpatch.com/

The main idea is that you can get the sequence at any time with toArray on your Node.js app, and you can easily send it to your user (without sending the whole array).

Thoughts anyone?

neumino avatar Mar 31 '15 03:03 neumino

I would prefer it if range was just an array by default and .toPatch() implemented the JSON patch behavior you described. I think the more common case is that people will just emit the entire array to the client each time.

marshall007 avatar May 23 '15 02:05 marshall007

any chance this feature gonna make it?

singggum3b avatar Sep 15 '16 04:09 singggum3b

Hum the API hasn't been quite nailed down so there's more work needed here.

neumino avatar Sep 16 '16 02:09 neumino