-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: subject filtering pagination #1710
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -429,15 +429,15 @@ func (engine *SubjectFilter) subjectFilterDirectRelation( | |
// NewContextualRelationships() creates a ContextualRelationships instance from tuples in the request. | ||
// QueryRelationships() then uses the filter to find and return matching relationships. | ||
var cti *database.TupleIterator | ||
cti, err = storageContext.NewContextualTuples(request.GetContext().GetTuples()...).QueryRelationships(filter, database.NewCursorPagination(database.Cursor(request.GetContinuousToken()), database.Sort("subject_id"))) | ||
cti, err = storageContext.NewContextualTuples(request.GetContext().GetTuples()...).QueryRelationships(filter, database.NewCursorPagination()) | ||
if err != nil { | ||
return subjectFilterEmpty(), err | ||
Comment on lines
+432
to
434
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle pagination tokens for scalability in At lines 432-434, you're using Consider modifying the pagination to handle tokens and set appropriate limits. This could involve passing pagination parameters from the request or defining default limits to ensure efficient data retrieval. -cti, err = storageContext.NewContextualTuples(request.GetContext().GetTuples()...).QueryRelationships(filter, database.NewCursorPagination())
+pagination := database.NewCursorPagination()
+if request.GetContinuousToken() != "" {
+ pagination.Token = request.GetContinuousToken()
+}
+cti, err = storageContext.NewContextualTuples(request.GetContext().GetTuples()...).QueryRelationships(filter, pagination) Also, ensure that the
|
||
} | ||
|
||
// Query the relationships for the entity in the request. | ||
// TupleFilter helps in filtering out the relationships for a specific entity and a permission. | ||
var rit *database.TupleIterator | ||
rit, err = engine.dataReader.QueryRelationships(ctx, request.GetTenantId(), filter, request.GetMetadata().GetSnapToken(), database.NewCursorPagination(database.Cursor(request.GetContinuousToken()), database.Sort("subject_id"))) | ||
rit, err = engine.dataReader.QueryRelationships(ctx, request.GetTenantId(), filter, request.GetMetadata().GetSnapToken(), database.NewCursorPagination()) | ||
if err != nil { | ||
return subjectFilterEmpty(), err | ||
Comment on lines
+440
to
442
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure consistent pagination handling in data reader queries At lines 440-442, similar to the previous comment, you're using Consider implementing pagination handling as suggested in the previous comment to ensure consistency. Here's an example: -pagination := database.NewCursorPagination()
+pagination := database.NewCursorPagination()
+if request.GetContinuousToken() != "" {
+ pagination.Token = request.GetContinuousToken()
+}
rit, err = engine.dataReader.QueryRelationships(ctx, request.GetTenantId(), filter, request.GetMetadata().GetSnapToken(), pagination) This ensures that both sources respect the pagination parameters, providing a consistent interface for clients.
|
||
} | ||
|
@@ -695,7 +695,7 @@ func subjectFilterUnion(ctx context.Context, functions []SubjectFilterFunction, | |
encounteredWildcard = true | ||
// Collect any additional IDs alongside "<>", treat them as exclusions | ||
for _, id := range d.resp { | ||
if id != "<>" && !slices.Contains(excludedIds, id) { | ||
if id != ALL && !slices.Contains(excludedIds, id) { | ||
excludedIds = append(excludedIds, id) | ||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure pagination logic handles all subjects correctly.
In the loop for retrieving subject IDs, consider handling potential scenarios where the number of subjects exceeds the page size to avoid missing any subjects due to pagination issues.
Apply this diff to adjust the pagination handling:
📝 Committable suggestion