Skip to content
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

Merged
merged 2 commits into from
Oct 4, 2023

Conversation

bradengroom
Copy link
Contributor

This updates the mysql datastore to compare tuples without stringifying.

@bradengroom bradengroom requested a review from a team October 3, 2023 01:20
@github-actions github-actions bot added area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Oct 3, 2023
Comment on lines +275 to +276
// 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)
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@vroldanbet vroldanbet left a 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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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

@bradengroom
Copy link
Contributor Author

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.

@bradengroom bradengroom requested a review from vroldanbet October 3, 2023 22:27
Copy link
Contributor

@vroldanbet vroldanbet left a 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! 🎉

@vroldanbet vroldanbet added this pull request to the merge queue Oct 4, 2023
Merged via the queue into authzed:main with commit 9e6080a Oct 4, 2023
25 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants