-
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
Conversation
// 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) |
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.
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 comment
The 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.
430ff42
to
cd07e1d
Compare
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.
Thanks for your contribution! ✨ Changes look good to me, added some minor feedback
return lhs.ObjectId == rhs.ObjectId && lhs.Relation == rhs.Relation && lhs.Namespace == rhs.Namespace | ||
} | ||
|
||
func OnrEqualOrWildcard(tpl, target *core.ObjectAndRelation) bool { |
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
Added tests for the equality functions. The caveat hashing function I found looked like it accepts a different type (protobuf struct?) than I have. I wasn’t sure how strongly you felt about using the hashing function, but I’m happy to look into it more if you want. |
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 looks good to me, thanks for contributing back to the project! 🎉
This updates the mysql datastore to compare tuples without stringifying.