Add support for basic cursors and limits to LookupSubjects#1379
Add support for basic cursors and limits to LookupSubjects#1379josephschorr wants to merge 1 commit intoauthzed:mainfrom
Conversation
da48a6b to
19099a2
Compare
21ae960 to
c386a05
Compare
vroldanbet
left a comment
There was a problem hiding this comment.
I didn't have time to finish the review, sorry! This is my first attempt. So far it's looking good, although I have a bunch of questions.
Something I noticed is that when one resumes with a cursor, we are evaluating the whole graph again and sending queries to the database, even though they will return empty. It works, but is a lot of work that is wasted after resuming, and will be directly proportional to the complexity of the schema. Ideally the evaluation of the schema can also resume from where the cursor left off, e.g. if permission view = a + b + c you'd restart evaluation at c if that's where you left when the limit was hit. It would spare a bunch of dispatching (network calls across SpiceDBs!) and DB roundtrips.
There was a problem hiding this comment.
can we merge this into the loop below?
There was a problem hiding this comment.
I did so, but I'm thinking maybe we just remove it entirely now? The field has been marked deprecated for a number of versions
There was a problem hiding this comment.
do we need to allocate a new encoded cursor each time here? Could we reuse the same proto instance and just modify the corresponding field? I did something as an optimization in the ReadRelationships streaming bits and helped a bunch with allocations and GC overhead. It would also spare us calling revision.String() repeatedly.
There was a problem hiding this comment.
It would be far less maintainable, but I'll see what I can do
There was a problem hiding this comment.
Done, but its a bit ugly
There was a problem hiding this comment.
After a second pass, I thought the new code could have a race. Perhaps it's not worth the trouble? I'll leave it up to you
There was a problem hiding this comment.
in not sure to understand how we guarantee that we do not skip found subjects that are alphabetically after the current cursor but that haven't been seen by the stream before.
There was a problem hiding this comment.
Because the stream always returns in sorted order from the root. That way, we are always guaranteed to have a defined ordering (alphabetical) coming out of each subproblem
There was a problem hiding this comment.
Doesn't that mean that we have to start collecting subjects from all subproblems before we can start streaming? We can make sure that each subproblem retrieves results in order from DB, but you still need to execute all of them in order to determine what's the first subject to stream?
There was a problem hiding this comment.
there had been some regressions recently around dispatches and I wonder if we could use a new test-case that checks the number of dispatches over a cursored LR call
There was a problem hiding this comment.
You mean over the LS call? We do now have the test for LR calls
There was a problem hiding this comment.
I mean testing for LS. The logic should be different enough that it warrants another set of tests?
There was a problem hiding this comment.
I see no use of the variadic allowedSubjectIds so please pass as a slice. NewSet should also support a slice - a lot of calls in the codebase that end up doing ... just to pass it to it.
There was a problem hiding this comment.
Changed here but not NewSet. We have some places where the variadic is helpful. If you like, I can add another NewSetFromSlice and change the call sites?
There was a problem hiding this comment.
yep I think that'd be a good idea
There was a problem hiding this comment.
Done and changed all the call sites
c386a05 to
137e08e
Compare
|
Updated |
137e08e to
1dec055
Compare
|
Rebased |
3202a4b to
b00913b
Compare
b00913b to
83a96b2
Compare
83a96b2 to
39f033f
Compare
|
Rebased |
57a79b9 to
07dbacd
Compare
vroldanbet
left a comment
There was a problem hiding this comment.
Doing a complete re-review to load all the context. First batch of feedback.
There was a problem hiding this comment.
The handling stream should handle all the elements up to the concrete limit, wouldn't it? From looking at the code, it would seem the only sole purpose is making sure the wildcard is sent, since in the worst-case scenario we stream up to the concrete limit, and we have to handle the potential +1 of the wildcard. Is that correct?
vroldanbet
left a comment
There was a problem hiding this comment.
@josephschorr last batch of feedback. Let's address this quickly so we don't loose the context and we can land it soon.
There was a problem hiding this comment.
I mean testing for LS. The logic should be different enough that it warrants another set of tests?
There was a problem hiding this comment.
After a second pass, I thought the new code could have a race. Perhaps it's not worth the trouble? I'll leave it up to you
07dbacd to
0c9fbb7
Compare
|
Updated |
0c9fbb7 to
1f765d0
Compare
This change supports a limit (called the "concrete limit") on LookupSubjects and will filter concrete subjects based on the returned cursor. This change does *not* filter intermediate lookups, which will be done in a followup PR.
1f765d0 to
e74c6f3
Compare
|
Moved to draft due to steelthread discovering a pagination bug |
|
@vroldanbet Is there any progress for this pr, we are still looking forward the pagination function of LookupSubjects. |
|
@karlwang1983 I will defer to @josephschorr, my role has been to review the code. |
|
Also looking forward to this one! |
|
Closing, as we will be taking a different approach to LookupSubjects pagination given that the current approach does not work as we intended |
This change supports a limit (called the "concrete limit") on LookupSubjects and will filter concrete subjects based on the returned cursor.
This change does not filter intermediate lookups, which will be done in a followup PR.