Hello spiced people 👋 I'm reading the docs to tr...
# spicedb
w
Hello spiced people 👋 I'm reading the docs to try and understand how to use the new paginated APIs (in particular LookupResources). I'm not seeing much, do you have an example of how to use pagination now?
v
pagination is not released yet - we released a new paginated
Datastore
implementation that allows us to expose the paginated APIs. The 1.21 release includes a new implementation of
ReadRelationships
that uses pagination under the hood, which means that it only reads as many tuples as the stream requests (roughly - it still over-reads, but nothing like before). The paginated versions of Lookup APIs is WIP and may land in 1.22
w
Right, so if I understand correctly, so far it's only useful for respecting
optional_limit
?
v
no, nothing provided via the API is being respected right now re: pagination. As I mentioned, it's only the (internal) Datastore API that has changed, in preparation to making applicable SpiceDB API paginable. I'm wondering if the fact that the buf API already shows pagination concepts be misleading here
w
Maybe I read what I wanted in the "Datastore accesses are now paginated to efficiently handle large Reads and LookUps" announcement 😄
> I'm wondering if the fact that the buf API already shows pagination concepts be misleading here I wouldn't know how to use the cursor from the API, so I'd say it's at least "confusing"
v
could you expand? 🙏🏻 cursor and limit relatively standard across the industry, what part makes it confusing? The fact that its used over a streaming API?
d
I think the important part here is "already", not the cursor/limit concept. I also thought 1.21 already has pagination support. You are saying it has not, which is fine, but then it is confusing that the public API already holds these non-supported concepts as part of its contract, and thus tricks ppl in thinking they are already ready to be used 🙂
v
yeah that's is fair - it's a side effect of SpiceDB API being decoupled from SpiceDB repo itself
so it has its own lifecycle, and it would seem to suggest that, whatever the latest SpiceDB version is, it's what shows in buf website
w
I'd expect a
limit
property to come with an
offset
property. I'd expect
cursor
and
limit
to be 2 unrelated concepts. I don't really understand ATM what
optional_cursor
is for: what can I use it for?
v
are you perhaps thinking of offset-based pagination instead of cursor-based pagination? Cursor is literally a relationship where to continue paginating from. So, in the upcoming paginated
LookupResources
, you'd be saying something like "fetch the next X elements (i.e. limit) starting from this last known result (i.e. cursor)". It's optional because it has to be retrofitted into an API that didn't have it before, but also because on the first call you will not have a cursor
d
1st call: optional_limit = 50 1st response: after_result_cursor = 50 => 1st 50 entries are shown. 2nd call: optional_cursor=50, limit = 50 2nd response: after_result_cursor=100 => 51th to 100th result are shown 3rd ... ... ... if I understand it correctly.
w
> So, in the upcoming paginated LookupResources , you'd be saying something like "fetch the next X elements (i.e. limit) starting from this last known result (i.e. cursor)". It's optional because it has to be retrofitted into an API that didn't have it before, but also because on the first call you will not have a cursor OK. But I am confused as to why I can use these for pagination, yet you're saying that pagination is "upcoming"?
v
right, that would be related to what @dguhr84 said above: it's the problem of the decoupled lifecycle of the API definition and the
SpiceDB
repo
w
> right, that would be related to what @dguhr84 said above: it's the problem of the decoupled lifecycle of the API definition and the SpiceDB repo I just got that indeed 😄
v
the API shows as if it's already there, when in reality that version of the API isn't yet consumed by a released version of SpiceDB
w
okay all the pieces of the puzzle fit now
These docs are indeed confusing 🙂
v
it's fair feedback 💯 To be clear, you are referring to https://buf.build/authzed/api right?
buf right now its treated like a git repo, so what you are seeing in the website would be
main
. That aligns with what you see in github.com/authzed/spicedb - you are welcomed with
main
- but that's not necessarily what users expect from it: you would like to see the actual latest released version, not
main
of the API
w
Yes, https://buf.build/authzed/api/docs/main:authzed.api.v1 to be precise, which is linked from the docs website
v
as a side note - offset pagination does not scale, because it requires you to read all previous rows in order to determine what the n-th row is. I'm sure y'all know that already, but I always found this blogpost captures the problem well https://use-the-index-luke.com/no-offset
in case y'all interested, the paginated LookupResources implementation is already currently in review https://github.com/authzed/spicedb/pull/1296
we are also working on a
DeleteRelationship
with limits, so you can delete in batches
7 Views