Hello! My name is Niv, and I’m a new
# spicedb
r
Hello! My name is Niv, and I’m a new user of SpiceDB 😊 I’m interested in using LookupResources and LookupSubjects. For robustness, I’d like to use cursor-based pagination. I saw in the documentation that cursor pagination is not supported for LookupSubjects. However, when I looked at the internal interfaces in the code, it seems like it is supported there. Is this a mistake in the documentation, or am I misunderstanding something? https://cdn.discordapp.com/attachments/844600078948630559/1452316263354466367/image.png?ex=69894f2b&is=6987fdab&hm=d5f5b5e406e6b42092f8bc6ec10e7ec5e66364bce539b13098d5f66f989d8460& https://cdn.discordapp.com/attachments/844600078948630559/1452316263568248996/image.png?ex=69894f2b&is=6987fdab&hm=9d63e9666faa1f5daab1c889a5b708085c64d6b85e4fa2e729702202af97654c&
y
we added it to the API because we were going to implement it, and then when we went to do the implementation we realized that there were issues with our planned implementation - turns out cursoring and wildcard subjects don't play nicely together. we should update that documentation.
r
Hey thanks for the answer, we would like to implement pagination for the following use cases: * all ReBAC list and lookup APIs (lookupResources, lookupSubjects, expand) must support cursor-based pagination for scalability. 1. What is the next page of results for this resource lookup? 2. What is the next page of subjects for this relation or permission? 3. Give me the next page of accessible resources for user X.
Copy code
const subjectContext = {
    tenantId: 'tenant-123',
    userId: 'user-456'
};

// First page
let result = await e10sClient.lookupResources(
    subjectContext,
    'document',
    'read',
    {
        limit: 50  // Get 50 results at a time
    }
);

console.log(`Page 1: Found ${result.totalReturned} documents`);
console.log(result.resources);

// Second page (if more results exist)
if (result.hasMore && result.cursor) {
    result = await e10sClient.lookupResources(
        subjectContext,
        'document',
        'read',
        {
            limit: 50,
            cursor: result.cursor  // Use cursor from previous response
        }
    );
    
    console.log(`Page 2: Found ${result.totalReturned} more documents`);
    console.log(result.resources);
}
what does it mean from the user POV , what will be the impact, as we need a way to provide our customers with pagination to filter their results . Thank you for your time!
y
what are you using LookupSubjects for?
it's common to need pagination for LookupResources but I haven't heard folks needing it for LookupSubjects nearly as often
r
Thanks again. This API is used to query large datasets, for example, thousands of users who have access to a document, We are using hierarchies with more then 3 hops.
y
i'd test it. thousands of users doesn't sound like too many for lookupsubjects, and you'd do the pagination at your DB level, not at the SpiceDB level. SpiceDB would just be adding a WHERE clause.
r
thanksssss
what about millions ?
y
yeah, that'd be too many, but i also have a hard time imagining what kind of question you'd want to ask where the answer is millions of users but not all of the users
r

https://tenor.com/iSsTILVz6qd.gif▾

y
sure thing
r
Hey @yetitwo is order by supported in lookup functions?
Thanksss
y
no. you can't do an order on a distributed graph traversal without collecting all of the results in memory, which we by and large want to avoid.
if you use a cursor, you're guaranteed to get the same traversal order on subsequent calls so that the cursor functions, but we don't provide any guarantees beyond that
r
Wow thanks !!
Make sense lol
y
sure thing
17 Views