-
Notifications
You must be signed in to change notification settings - Fork 279
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
Extend support for relationship filtering and add relationship filtering to other APIs #1739
Conversation
3179299
to
ca4cc05
Compare
// If there are filters, we need to check if the update matches any of them. | ||
matched := false | ||
for _, filter := range filters { | ||
// TODO(jschorr): Maybe we should add TestRelationship to avoid the conversion? |
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.
This seems like a good compromise to avoid unnecessary allocations 🙏🏻
4b1ff59
to
cfa8e45
Compare
func (sqf SchemaQueryFilterer) MustFilterWithResourceIDPrefix(prefix string) SchemaQueryFilterer { | ||
updated, err := sqf.FilterWithResourceIDPrefix(prefix) | ||
if err != nil { | ||
panic(err) |
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.
I see that the other filters use this pattern as well, but I thought we had decided to avoid panics outside of tests?
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.
This function is only called from tests
err, | ||
codes.InvalidArgument, | ||
spiceerrors.ForReason( | ||
v1.ErrorReason_ERROR_REASON_UNSPECIFIED, |
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.
any reason to wait on defining a real reason here?
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.
It requires an API repo change and I didn't want to block this change, so I left it as a TODO
} | ||
|
||
return atRevision, cur, nil | ||
return atRevision, decoded.GetV1().GetSections()[0], cur, nil |
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.
maybe a note about what this new return value is?
cfa8e45
to
7acac9a
Compare
index := indexNamespace | ||
args := []any{filter.ResourceType} | ||
if filter.OptionalResourceRelation != "" { | ||
index := indexNamespace + "_prefix" |
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.
can you explain why _prefix
was added to the default index? No index like that can be found in spicedb/internal/datastore/memdb/schema.go
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.
Its a built-in to the backing memdb for prefix filtering; I'll add a note
case err == nil: | ||
break | ||
nsClauses = append(nsClauses, sq.Eq{colNamespace: nsName}) |
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.
a bit weird to see this here but seems correct
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.
Has this changed appreciably?
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.
it hasn't, just surprised me to see logic next to error handling
@@ -647,29 +669,30 @@ func queryForEach( | |||
return cur, nil | |||
} | |||
|
|||
func decodeCursor(ds datastore.Datastore, encoded *v1.Cursor) (datastore.Revision, *core.RelationTuple, error) { | |||
func decodeCursor(ds datastore.Datastore, encoded *v1.Cursor) (datastore.Revision, string, *core.RelationTuple, error) { |
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.
not sure to understand if the format of the cursor has changed, and if this is a breaking change.
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.
yes, it has: we now have a namespace contained in it
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.
in that case, don't we have a mechanism to version cursors already in place, and that we should be using it?
e.g. a cursor V1 is not compatible with cursor V2 or viceversa
|
||
// Datastore namespace order might not be exactly the same as go namespace order | ||
// so we shouldn't assume cursors are valid across namespaces | ||
cur = nil |
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.
can you clarify what happened here? I see a similar change was introduced earlier in the loop to make sure the cursor is reset for each iteration as the namespace changes
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.
Not sure I follow
… relationships APIs
7acac9a
to
3c735d8
Compare
Updated. Good catch on the deletion side: it was missing handlers for the prefix filtering |
3c735d8
to
d76d12c
Compare
Important
If a relationships filter is used without a resource type, there can be a performance impact due to the existing indexes all starting with the resource type. We may examine adding additional indexes in the future, but for now, the performance impact should be noted
resource_type
, and a prefix for object IDsWith this change, all objects can now be removed from the datastore with two calls (once with the object ID as the resource ID and once with it as the subject ID).
Fixes #315 (more or less; its two calls instead of one)