H-847, H-4433: Use `viewEntity` policy over `viewer` relationships in the Graph
🌟 What is the purpose of this PR?
I prepared everything in order to use the new viewEntity policy action and stop relying on SpiceDB for entity queries. This changes the implementation in the Graph.
🚫 Blocked by
- #7350
🔍 What does this change?
All usages of EntityPermission::View has been replaced with the appropriated call to the new policy engine.
Pre-Merge Checklist 🚀
🚢 Has this modified a publishable library?
This PR:
- [x] does not modify any publishable blocks or libraries, or modifications do not need publishing
📜 Does this require a change to the docs?
The changes in this PR:
- [x] are internal and do not require a docs change
🕸️ Does this require a change to the Turbo Graph?
The changes in this PR:
- [x] do not affect the execution graph
🐾 Next steps
- https://github.com/hashintel/hash/pull/7351
🛡 What tests cover this?
Pretty much every test around entities implicitly tests this
❓ How to test this?
Start the application and make sure everything is still working as expected
Codecov Report
Attention: Patch coverage is 17.44966% with 123 lines in your changes missing coverage. Please review.
Project coverage is 53.14%. Comparing base (
7861144) to head (b5fe8ad). Report is 3 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #7352 +/- ##
==========================================
+ Coverage 52.75% 53.14% +0.39%
==========================================
Files 1079 1079
Lines 95833 95853 +20
Branches 4431 4435 +4
==========================================
+ Hits 50557 50942 +385
+ Misses 44324 43955 -369
- Partials 952 956 +4
| Flag | Coverage Δ | |
|---|---|---|
| apps.hash-ai-worker-ts | 1.32% <ø> (ø) |
|
| apps.hash-api | 0.00% <ø> (ø) |
|
| local.hash-backend-utils | 3.68% <ø> (ø) |
|
| local.hash-graph-sdk | 0.00% <ø> (ø) |
|
| local.hash-isomorphic-utils | 0.00% <ø> (ø) |
|
| rust.hash-graph-api | 3.43% <ø> (ø) |
|
| rust.hash-graph-authorization | 32.39% <80.00%> (+1.77%) |
:arrow_up: |
| rust.hash-graph-postgres-store | 20.04% <12.94%> (+0.61%) |
:arrow_up: |
| rust.hash-graph-store | 36.87% <ø> (+3.90%) |
:arrow_up: |
| rust.hash-graph-validation | 83.30% <ø> (ø) |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
VSCode being stupid with git rebasing...
Benchmark results
@rust/hash-graph-benches – Integrations
scaling_read_entity_linkless
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | 1 entities | $$15.8 \mathrm{ms} \pm 77.9 \mathrm{μs}\left({\color{red}156 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 10 entities | $$15.7 \mathrm{ms} \pm 73.1 \mathrm{μs}\left({\color{red}150 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 10000 entities | $$22.5 \mathrm{ms} \pm 164 \mathrm{μs}\left({\color{red}21.9 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 100 entities | $$15.9 \mathrm{ms} \pm 76.3 \mathrm{μs}\left({\color{red}142 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 1000 entities | $$15.7 \mathrm{ms} \pm 112 \mathrm{μs}\left({\color{red}122 \mathrm{\%}}\right) $$ | Flame Graph |
representative_read_entity_type
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| get_entity_type_by_id | Account ID: bf5a9ef5-dc3b-43cf-a291-6210c0321eba |
$$6.04 \mathrm{ms} \pm 31.9 \mathrm{μs}\left({\color{gray}0.550 \mathrm{\%}}\right) $$ | Flame Graph |
representative_read_multiple_entities
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_property | depths: DT=0, PT=2, ET=2, E=2 | $$120 \mathrm{ms} \pm 559 \mathrm{μs}\left({\color{red}99.1 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_property | depths: DT=0, PT=0, ET=2, E=2 | $$115 \mathrm{ms} \pm 947 \mathrm{μs}\left({\color{red}108 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_property | depths: DT=0, PT=0, ET=0, E=2 | $$109 \mathrm{ms} \pm 665 \mathrm{μs}\left({\color{red}123 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_property | depths: DT=0, PT=0, ET=0, E=0 | $$97.4 \mathrm{ms} \pm 672 \mathrm{μs}\left({\color{red}118 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_property | depths: DT=255, PT=255, ET=255, E=255 | $$135 \mathrm{ms} \pm 1.27 \mathrm{ms}\left({\color{red}82.9 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_property | depths: DT=2, PT=2, ET=2, E=2 | $$123 \mathrm{ms} \pm 1.05 \mathrm{ms}\left({\color{red}93.2 \mathrm{\%}}\right) $$ | Flame Graph |
| link_by_source_by_property | depths: DT=0, PT=2, ET=2, E=2 | $$213 \mathrm{ms} \pm 1.11 \mathrm{ms}\left({\color{red}121 \mathrm{\%}}\right) $$ | Flame Graph |
| link_by_source_by_property | depths: DT=0, PT=0, ET=2, E=2 | $$209 \mathrm{ms} \pm 2.22 \mathrm{ms}\left({\color{red}128 \mathrm{\%}}\right) $$ | Flame Graph |
| link_by_source_by_property | depths: DT=0, PT=0, ET=0, E=2 | $$201 \mathrm{ms} \pm 883 \mathrm{μs}\left({\color{red}142 \mathrm{\%}}\right) $$ | Flame Graph |
| link_by_source_by_property | depths: DT=0, PT=0, ET=0, E=0 | $$147 \mathrm{ms} \pm 1.22 \mathrm{ms}\left({\color{red}232 \mathrm{\%}}\right) $$ | Flame Graph |
| link_by_source_by_property | depths: DT=255, PT=255, ET=255, E=255 | $$231 \mathrm{ms} \pm 1.54 \mathrm{ms}\left({\color{red}112 \mathrm{\%}}\right) $$ | Flame Graph |
| link_by_source_by_property | depths: DT=2, PT=2, ET=2, E=2 | $$219 \mathrm{ms} \pm 810 \mathrm{μs}\left({\color{red}119 \mathrm{\%}}\right) $$ | Flame Graph |
scaling_read_entity_complete_one_depth
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | 50 entities | $$367 \mathrm{ms} \pm 2.12 \mathrm{ms}\left({\color{red}23.6 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 1 entities | $$72.1 \mathrm{ms} \pm 228 \mathrm{μs}\left({\color{red}171 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 10 entities | $$119 \mathrm{ms} \pm 438 \mathrm{μs}\left({\color{red}84.1 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 5 entities | $$83.6 \mathrm{ms} \pm 448 \mathrm{μs}\left({\color{red}147 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 25 entities | $$256 \mathrm{ms} \pm 1.77 \mathrm{ms}\left({\color{red}34.5 \mathrm{\%}}\right) $$ | Flame Graph |
scaling_read_entity_complete_zero_depth
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | 50 entities | $$17.3 \mathrm{ms} \pm 118 \mathrm{μs}\left({\color{red}84.5 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 1 entities | $$15.8 \mathrm{ms} \pm 99.5 \mathrm{μs}\left({\color{red}153 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 10 entities | $$15.6 \mathrm{ms} \pm 112 \mathrm{μs}\left({\color{red}146 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 5 entities | $$15.8 \mathrm{ms} \pm 89.8 \mathrm{μs}\left({\color{red}154 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | 25 entities | $$17.5 \mathrm{ms} \pm 76.3 \mathrm{μs}\left({\color{red}139 \mathrm{\%}}\right) $$ | Flame Graph |
representative_read_entity
| Function | Value | Mean | Flame graphs |
|---|---|---|---|
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1 |
$$30.6 \mathrm{ms} \pm 279 \mathrm{μs}\left({\color{red}45.9 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/building/v/1 |
$$29.2 \mathrm{ms} \pm 287 \mathrm{μs}\left({\color{gray}2.97 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/block/v/1 |
$$30.7 \mathrm{ms} \pm 230 \mathrm{μs}\left({\color{red}48.0 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/book/v/1 |
$$29.6 \mathrm{ms} \pm 282 \mathrm{μs}\left({\color{gray}4.16 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/person/v/1 |
$$30.0 \mathrm{ms} \pm 257 \mathrm{μs}\left({\color{red}42.8 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/playlist/v/1 |
$$30.0 \mathrm{ms} \pm 373 \mathrm{μs}\left({\color{red}44.3 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/song/v/1 |
$$30.9 \mathrm{ms} \pm 311 \mathrm{μs}\left({\color{red}47.9 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/organization/v/1 |
$$30.1 \mathrm{ms} \pm 329 \mathrm{μs}\left({\color{red}23.2 \mathrm{\%}}\right) $$ | Flame Graph |
| entity_by_id | entity type ID: https://blockprotocol.org/@alice/types/entity-type/page/v/2 |
$$29.5 \mathrm{ms} \pm 272 \mathrm{μs}\left({\color{red}35.3 \mathrm{\%}}\right) $$ | Flame Graph |