Skip to content

Commit a39b1a4

Browse files
torazartorazar
andauthored
fix: ensure timeouts applied at repo level (#784)
Co-authored-by: torazar <tack404@gmail.com>
1 parent fc9c4c6 commit a39b1a4

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

lib/data_layer.ex

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,13 @@ defmodule AshPostgres.DataLayer do
866866
with_savepoint(repo, query, fn ->
867867
repo.all(
868868
query,
869-
AshSql.repo_opts(repo, AshPostgres.SqlImplementation, nil, nil, resource)
869+
AshSql.repo_opts(
870+
repo,
871+
AshPostgres.SqlImplementation,
872+
repo_timeout(query),
873+
nil,
874+
resource
875+
)
870876
)
871877
|> AshSql.Query.remap_mapped_fields(query)
872878
|> then(fn results ->
@@ -892,6 +898,12 @@ defmodule AshPostgres.DataLayer do
892898
defp no_table?(%{from: %{source: {"", _}}}), do: true
893899
defp no_table?(_), do: false
894900

901+
defp repo_timeout(%{__ash_bindings__: %{context: context}}) when is_map(context) do
902+
get_in(context, [:data_layer, :timeout]) || (context[:action] && context[:action].timeout)
903+
end
904+
905+
defp repo_timeout(_), do: nil
906+
895907
@impl true
896908
def functions(resource) do
897909
config = AshPostgres.DataLayer.Info.repo(resource, :mutate).config()
@@ -1046,7 +1058,7 @@ defmodule AshPostgres.DataLayer do
10461058
AshSql.repo_opts(
10471059
repo,
10481060
AshPostgres.SqlImplementation,
1049-
nil,
1061+
repo_timeout(query),
10501062
nil,
10511063
source_resource
10521064
)
@@ -1103,7 +1115,13 @@ defmodule AshPostgres.DataLayer do
11031115
results =
11041116
repo.all(
11051117
lateral_join_query,
1106-
AshSql.repo_opts(repo, AshPostgres.SqlImplementation, nil, nil, source_resource)
1118+
AshSql.repo_opts(
1119+
repo,
1120+
AshPostgres.SqlImplementation,
1121+
repo_timeout(lateral_join_query),
1122+
nil,
1123+
source_resource
1124+
)
11071125
)
11081126
|> AshSql.Query.remap_mapped_fields(
11091127
query,
@@ -1693,12 +1711,8 @@ defmodule AshPostgres.DataLayer do
16931711
Ash.Query.do_filter(query, expr)
16941712
end
16951713

1696-
defp get_subquery(query) do
1697-
case query do
1698-
%Ecto.SubQuery{query: query} -> query
1699-
%Ecto.Query{} -> query
1700-
end
1701-
end
1714+
defp get_subquery(%Ecto.Query{} = query), do: query
1715+
defp get_subquery(%Ecto.SubQuery{query: query}), do: query
17021716

17031717
@doc false
17041718
def set_subquery_prefix(data_layer_query, source_query, resource) do

0 commit comments

Comments
 (0)