openfga icon indicating copy to clipboard operation
openfga copied to clipboard

pgsql backend: don't insert model if already exists (hash models)

Open awoimbee opened this issue 3 months ago • 3 comments

Description

  • Store a hash of AuthorizationModels
  • If it is requested to store a new model, but the store already contains one with the same hash, it can return the already existing one

What problem is being solved?

Sending authorization model twice duplicates it

References

Closes #811

Review Checklist

  • [x] I have clicked on "allow edits by maintainers".
  • [ ] I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • [x] The correct base branch is being used, if not main
  • [ ] I have added tests to validate that the change in functionality is working as expected

TODO:

  • Make the tests pass (they don't seem to work on my machine)
  • Write tests for this feature

I absolutely suck at Go, I'm not sure I can finish this PR.

awoimbee avatar Oct 07 '25 09:10 awoimbee

[!IMPORTANT]

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Oct 07 '25 09:10 coderabbitai[bot]

If the provided model is exactly the same, but one type's relations are defined in a slightly different order, will this produce a consistent hash? Looking over the implementation, it would not appear to.

senojj avatar Oct 13 '25 13:10 senojj

will this produce a consistent hash?

#811 is about caching the exact same request, we don't care about semantic equality. IMO OpenFGA doesn't have to guarantee caching in all cases and for all storage backends, it just has to try.

awoimbee avatar Oct 13 '25 14:10 awoimbee