mirror of
https://github.com/ash-project/ash.git
synced 2024-09-19 13:03:02 +12:00
fix: properly clean calculation dependency values, and don't unload them with lazy?
This commit is contained in:
parent
926762cf38
commit
8ba9eeb3b4
2 changed files with 53 additions and 22 deletions
|
@ -508,10 +508,21 @@ defmodule Ash.Actions.Read.Calculations do
|
||||||
if to_load do
|
if to_load do
|
||||||
Enum.map(records, fn record ->
|
Enum.map(records, fn record ->
|
||||||
case record do
|
case record do
|
||||||
%Ash.NotLoaded{} -> record
|
%Ash.NotLoaded{} ->
|
||||||
%Ash.ForbiddenField{} -> record
|
record
|
||||||
nil -> record
|
|
||||||
record -> Map.put(record, to_load, Map.get(record.calculations, source))
|
%Ash.ForbiddenField{} ->
|
||||||
|
record
|
||||||
|
|
||||||
|
nil ->
|
||||||
|
record
|
||||||
|
|
||||||
|
record ->
|
||||||
|
{new_val, calculations} = Map.pop(record.calculations, source)
|
||||||
|
|
||||||
|
record
|
||||||
|
|> Map.put(to_load, new_val)
|
||||||
|
|> Map.put(:calculations, calculations)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
|
@ -527,11 +538,11 @@ defmodule Ash.Actions.Read.Calculations do
|
||||||
record
|
record
|
||||||
|
|
||||||
record ->
|
record ->
|
||||||
Map.update!(
|
{new_val, calculations} = Map.pop(record.calculations, source)
|
||||||
record,
|
|
||||||
:calculations,
|
record
|
||||||
&Map.put(&1, to_name, Map.get(record.calculations, source))
|
|> Map.update!(:calculations, &Map.put(&1, to_name, new_val))
|
||||||
)
|
|> Map.put(:calculations, calculations)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -540,10 +551,21 @@ defmodule Ash.Actions.Read.Calculations do
|
||||||
if to_load do
|
if to_load do
|
||||||
Enum.map(records, fn record ->
|
Enum.map(records, fn record ->
|
||||||
case record do
|
case record do
|
||||||
%Ash.NotLoaded{} -> record
|
%Ash.NotLoaded{} ->
|
||||||
%Ash.ForbiddenField{} -> record
|
record
|
||||||
nil -> record
|
|
||||||
record -> Map.put(record, to_load, Map.get(record.aggregates, source))
|
%Ash.ForbiddenField{} ->
|
||||||
|
record
|
||||||
|
|
||||||
|
nil ->
|
||||||
|
record
|
||||||
|
|
||||||
|
record ->
|
||||||
|
{new_val, aggregates} = Map.pop(record.aggregates, source)
|
||||||
|
|
||||||
|
record
|
||||||
|
|> Map.put(to_load, new_val)
|
||||||
|
|> Map.put(:aggregates, aggregates)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
|
@ -559,18 +581,23 @@ defmodule Ash.Actions.Read.Calculations do
|
||||||
record
|
record
|
||||||
|
|
||||||
record ->
|
record ->
|
||||||
Map.update!(
|
{new_val, aggregates} = Map.pop(record.aggregates, source)
|
||||||
record,
|
|
||||||
:aggregates,
|
record
|
||||||
&Map.put(&1, to_name, Map.get(record.calculations, source))
|
|> Map.update!(:aggregates, &Map.put(&1, to_name, new_val))
|
||||||
)
|
|> Map.put(:aggregates, aggregates)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
{{path, {:rel, rel_name}, _, _}, source}, records ->
|
{{path, {:rel, rel_name}, _, _}, source}, records ->
|
||||||
update_at_path(records, path, fn record ->
|
records
|
||||||
Map.put(record, rel_name, Map.get(record.calculations, source))
|
|> update_at_path(path, fn record ->
|
||||||
|
{new_val, calculations} = Map.pop(record.calculations, source)
|
||||||
|
|
||||||
|
record
|
||||||
|
|> Map.put(rel_name, new_val)
|
||||||
|
|> Map.put(:calculations, calculations)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1279,8 +1279,12 @@ defmodule Ash.Actions.Read do
|
||||||
|> Map.update!(:calculations, fn calculations ->
|
|> Map.update!(:calculations, fn calculations ->
|
||||||
loaded_keys =
|
loaded_keys =
|
||||||
calculations
|
calculations
|
||||||
|> Enum.filter(fn {_key, calc} ->
|
|> Enum.filter(fn
|
||||||
Ash.Resource.loaded?(initial_data, calc)
|
{{:__calc_dep__, _}, _} ->
|
||||||
|
false
|
||||||
|
|
||||||
|
{_key, calc} ->
|
||||||
|
Ash.Resource.loaded?(initial_data, calc)
|
||||||
end)
|
end)
|
||||||
|> Enum.map(&elem(&1, 0))
|
|> Enum.map(&elem(&1, 0))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue