mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
fix: convert %{__struct__: T}
into %T{}
(#947)
This commit is contained in:
parent
e6315e2928
commit
a85f559a20
3 changed files with 16 additions and 16 deletions
|
@ -26,7 +26,7 @@ defmodule Ash.Actions.Helpers do
|
||||||
|
|
||||||
def rollback_if_in_transaction(success, _, _), do: success
|
def rollback_if_in_transaction(success, _, _), do: success
|
||||||
|
|
||||||
def validate_calculation_load!(%{__struct__: Ash.Query}, module) do
|
def validate_calculation_load!(%Ash.Query{}, module) do
|
||||||
raise """
|
raise """
|
||||||
`#{inspect(module)}.load/3` returned a query.
|
`#{inspect(module)}.load/3` returned a query.
|
||||||
|
|
||||||
|
@ -39,13 +39,13 @@ defmodule Ash.Actions.Helpers do
|
||||||
|
|
||||||
def validate_calculation_load!(other, _), do: other
|
def validate_calculation_load!(other, _), do: other
|
||||||
|
|
||||||
defp set_context(%{__struct__: Ash.Changeset} = changeset, context),
|
defp set_context(%Ash.Changeset{} = changeset, context),
|
||||||
do: Ash.Changeset.set_context(changeset, context)
|
do: Ash.Changeset.set_context(changeset, context)
|
||||||
|
|
||||||
defp set_context(%{__struct__: Ash.Query} = query, context),
|
defp set_context(%Ash.Query{} = query, context),
|
||||||
do: Ash.Query.set_context(query, context)
|
do: Ash.Query.set_context(query, context)
|
||||||
|
|
||||||
defp set_context(%{__struct__: Ash.ActionInput} = action_input, context),
|
defp set_context(%Ash.ActionInput{} = action_input, context),
|
||||||
do: Ash.ActionInput.set_context(action_input, context)
|
do: Ash.ActionInput.set_context(action_input, context)
|
||||||
|
|
||||||
def add_process_context(api, query_or_changeset, opts) do
|
def add_process_context(api, query_or_changeset, opts) do
|
||||||
|
@ -117,19 +117,19 @@ defmodule Ash.Actions.Helpers do
|
||||||
|> Map.put_new(:authorize?, false)
|
|> Map.put_new(:authorize?, false)
|
||||||
|
|
||||||
case query_or_changeset do
|
case query_or_changeset do
|
||||||
%{__struct__: Ash.ActionInput} ->
|
%Ash.ActionInput{} ->
|
||||||
query_or_changeset
|
query_or_changeset
|
||||||
|> Ash.ActionInput.set_context(context)
|
|> Ash.ActionInput.set_context(context)
|
||||||
|> Ash.ActionInput.set_context(%{private: private_context})
|
|> Ash.ActionInput.set_context(%{private: private_context})
|
||||||
|> Ash.ActionInput.set_tenant(query_or_changeset.tenant || opts[:tenant])
|
|> Ash.ActionInput.set_tenant(query_or_changeset.tenant || opts[:tenant])
|
||||||
|
|
||||||
%{__struct__: Ash.Query} ->
|
%Ash.Query{} ->
|
||||||
query_or_changeset
|
query_or_changeset
|
||||||
|> Ash.Query.set_context(context)
|
|> Ash.Query.set_context(context)
|
||||||
|> Ash.Query.set_context(%{private: private_context})
|
|> Ash.Query.set_context(%{private: private_context})
|
||||||
|> Ash.Query.set_tenant(query_or_changeset.tenant || opts[:tenant])
|
|> Ash.Query.set_tenant(query_or_changeset.tenant || opts[:tenant])
|
||||||
|
|
||||||
%{__struct__: Ash.Changeset} ->
|
%Ash.Changeset{} ->
|
||||||
query_or_changeset
|
query_or_changeset
|
||||||
|> Ash.Changeset.set_context(context)
|
|> Ash.Changeset.set_context(context)
|
||||||
|> Ash.Changeset.set_context(%{
|
|> Ash.Changeset.set_context(%{
|
||||||
|
|
|
@ -83,7 +83,7 @@ defmodule Ash.Query.BooleanExpression do
|
||||||
def optimized_new(
|
def optimized_new(
|
||||||
:or,
|
:or,
|
||||||
%Eq{left: left, right: value} = left_op,
|
%Eq{left: left, right: value} = left_op,
|
||||||
%In{left: left, right: %{__struct__: MapSet} = mapset} = right
|
%In{left: left, right: %MapSet{} = mapset} = right
|
||||||
) do
|
) do
|
||||||
if can_optimize?(value) do
|
if can_optimize?(value) do
|
||||||
%{right | right: MapSet.put(mapset, value)}
|
%{right | right: MapSet.put(mapset, value)}
|
||||||
|
@ -95,7 +95,7 @@ defmodule Ash.Query.BooleanExpression do
|
||||||
def optimized_new(
|
def optimized_new(
|
||||||
:and,
|
:and,
|
||||||
%Eq{left: left, right: value} = left_expr,
|
%Eq{left: left, right: value} = left_expr,
|
||||||
%In{left: left, right: %{__struct__: MapSet} = mapset} = right
|
%In{left: left, right: %MapSet{} = mapset} = right
|
||||||
) do
|
) do
|
||||||
if can_optimize?(value) do
|
if can_optimize?(value) do
|
||||||
if MapSet.member?(mapset, value) do
|
if MapSet.member?(mapset, value) do
|
||||||
|
@ -111,7 +111,7 @@ defmodule Ash.Query.BooleanExpression do
|
||||||
def optimized_new(
|
def optimized_new(
|
||||||
:and,
|
:and,
|
||||||
%NotEq{left: left, right: value} = left_op,
|
%NotEq{left: left, right: value} = left_op,
|
||||||
%In{left: left, right: %{__struct__: MapSet} = mapset} = right_expr
|
%In{left: left, right: %MapSet{} = mapset} = right_expr
|
||||||
) do
|
) do
|
||||||
if can_optimize?(value) do
|
if can_optimize?(value) do
|
||||||
%{right_expr | right: MapSet.delete(mapset, value)}
|
%{right_expr | right: MapSet.delete(mapset, value)}
|
||||||
|
@ -166,8 +166,8 @@ defmodule Ash.Query.BooleanExpression do
|
||||||
|
|
||||||
def optimized_new(
|
def optimized_new(
|
||||||
:or,
|
:or,
|
||||||
%In{left: left, right: %{__struct__: MapSet} = left_values},
|
%In{left: left, right: %MapSet{} = left_values},
|
||||||
%In{left: left, right: %{__struct__: MapSet} = right_values} = right_expr
|
%In{left: left, right: %MapSet{} = right_values} = right_expr
|
||||||
) do
|
) do
|
||||||
%{right_expr | right: MapSet.union(left_values, right_values)}
|
%{right_expr | right: MapSet.union(left_values, right_values)}
|
||||||
end
|
end
|
||||||
|
@ -318,7 +318,7 @@ defmodule Ash.Query.BooleanExpression do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp can_optimize?(%{__struct__: MapSet} = mapset) do
|
defp can_optimize?(%MapSet{} = mapset) do
|
||||||
Enum.all?(mapset, &can_optimize?/1)
|
Enum.all?(mapset, &can_optimize?/1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -611,8 +611,8 @@ defmodule Ash.SatSolver do
|
||||||
def split_in_expressions(other, _), do: other
|
def split_in_expressions(other, _), do: other
|
||||||
|
|
||||||
def overlap?(
|
def overlap?(
|
||||||
%Ash.Query.Operator.In{left: left, right: %{__struct__: MapSet} = left_right},
|
%Ash.Query.Operator.In{left: left, right: %MapSet{} = left_right},
|
||||||
%Ash.Query.Operator.In{left: left, right: %{__struct__: MapSet} = right_right}
|
%Ash.Query.Operator.In{left: left, right: %MapSet{} = right_right}
|
||||||
) do
|
) do
|
||||||
if MapSet.equal?(left_right, right_right) do
|
if MapSet.equal?(left_right, right_right) do
|
||||||
false
|
false
|
||||||
|
@ -639,7 +639,7 @@ defmodule Ash.SatSolver do
|
||||||
|
|
||||||
def overlap?(
|
def overlap?(
|
||||||
%Ash.Query.Operator.Eq{left: left, right: left_right},
|
%Ash.Query.Operator.Eq{left: left, right: left_right},
|
||||||
%Ash.Query.Operator.In{left: left, right: %{__struct__: MapSet} = right_right}
|
%Ash.Query.Operator.In{left: left, right: %MapSet{} = right_right}
|
||||||
) do
|
) do
|
||||||
MapSet.member?(right_right, left_right)
|
MapSet.member?(right_right, left_right)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue