chore: fix recent calculation optimization to never prune authorization calcs

This commit is contained in:
Zach Daniel 2024-08-09 17:28:44 -04:00
parent 7991d84b0b
commit 5b40040c76
2 changed files with 16 additions and 10 deletions

View file

@ -2041,8 +2041,10 @@ defmodule Ash.Actions.Read.Calculations do
Enum.filter(calculations_in_query, &used?(ash_query, &1.name))}
end
defp used?(_ash_query, {:__ash_fields_are_visible__, _}), do: true
defp used?(ash_query, name) do
Map.has_key?(ash_query, name) ||
Map.has_key?(ash_query.calculations, name) ||
Enum.any?(ash_query.context[:calculation_dependencies] || [], fn {_source, dest} ->
name in dest
end)

View file

@ -676,16 +676,20 @@ defmodule Ash.Actions.Read do
record
record ->
Map.update!(record, :calculations, fn calculations ->
Map.update!(calculations, name, fn value ->
Ash.Type.rewrite(
type,
value,
[{:cleanup_field_auth, further_load}],
constraints
)
if Map.has_key?(record.calculations, name) do
Map.update!(record, :calculations, fn calculations ->
Map.update!(calculations, name, fn value ->
Ash.Type.rewrite(
type,
value,
[{:cleanup_field_auth, further_load}],
constraints
)
end)
end)
end)
else
record
end
end
nil ->