-
Notifications
You must be signed in to change notification settings - Fork 286
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
Compare tuples without stringifying #1562
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 |
---|---|---|
|
@@ -120,6 +120,14 @@ func StringWithoutCaveat(tpl *core.RelationTuple) string { | |
return fmt.Sprintf("%s@%s", StringONR(tpl.ResourceAndRelation), StringONR(tpl.Subject)) | ||
} | ||
|
||
func MustStringCaveat(caveat *core.ContextualizedCaveat) string { | ||
caveatString, err := StringCaveat(caveat) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return caveatString | ||
} | ||
|
||
// StringCaveat converts a contextualized caveat to a string. If the caveat is nil or empty, returns empty string. | ||
func StringCaveat(caveat *core.ContextualizedCaveat) (string, error) { | ||
if caveat == nil || caveat.CaveatName == "" { | ||
|
@@ -263,6 +271,11 @@ func Delete(tpl *core.RelationTuple) *core.RelationTupleUpdate { | |
} | ||
} | ||
|
||
func Equal(lhs, rhs *core.RelationTuple) bool { | ||
// TODO(jschorr): Use a faster method then string comparison for caveats. | ||
return OnrEqual(lhs.ResourceAndRelation, rhs.ResourceAndRelation) && OnrEqual(lhs.Subject, rhs.Subject) && MustStringCaveat(lhs.Caveat) == MustStringCaveat(rhs.Caveat) | ||
Comment on lines
+275
to
+276
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. We still stringify the caveat if everything else matches. There might be some optimizations that could be made here. For example, we could count the keys before stringifying. I'm not sure if this is worth doing. 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. There is a function in the codebase that computes a hash of the caveat context. I'm not sure that'd be faster than stringifying tho. |
||
} | ||
|
||
// MustToRelationship converts a RelationTuple into a Relationship. Will panic if | ||
// the RelationTuple does not validate. | ||
func MustToRelationship(tpl *core.RelationTuple) *v1.Relationship { | ||
|
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.
do we have tests for this?
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.
Nope! They aren't new really. I just relocated them from
internal/graph/check.go
. I can write tests though