cayley icon indicating copy to clipboard operation
cayley copied to clipboard

Cursors and Pagination

Open ghost opened this issue 10 years ago • 6 comments

Is there a way to offset a query, e.g: g.V().GetLimit(limit, offset)? Such a feature would be very handy for pagination purposes.

ghost avatar Aug 15 '14 15:08 ghost

What you really want (and I've been thinking about) is a cursor API. Eg, g.V().Cursor() (returns a cursor token) and then g.Cursor(token).Get(100) (returns 100 things from the prior query and a new cursor token).

This is effectively serialization of iterator trees for those playing at home, and is tangentially related to #64, in that you're building things that may need serialization, but is really just a feature unto itself.

barakmich avatar Aug 20 '14 20:08 barakmich

Any news on this feature - i think this is a must, without it, it would be hard to consider Cayley for production on anything dependent on pagination.

Also, how would the cursors be handled? Would the presence of cursors become an impediment on a live production deployment? If you have thousands of clients requesting paginated data, than you would have as many cursors as clients.

fisnik avatar Jan 19 '15 16:01 fisnik

Totally stealing @barakmich's words:

You can serialize the iterators and encode them and pass them as a token to the client. Thus, the client can just pass the token back and cayley deserializes it and continues iterating for results.

jzelinskie avatar Jul 30 '15 20:07 jzelinskie

I think there should be a streamable content type for Gizmo to allow

iddan avatar Jun 30 '19 14:06 iddan

@iddan This would require some interactive API like WebSockets or gRPC, but it's easier to implement than serializing the iterator chain (although achievable).

dennwc avatar Jul 28 '19 18:07 dennwc

This would require some interactive API like WebSockets or gRPC

I think writing multiple chunks to the HTTP message will be good enough. In Go's http I think you can use Response.Write() and Response.Flush(). We just need to use a different content type that supports partial messages like NDJSON or NQuads

iddan avatar Jul 29 '19 06:07 iddan