Skip to content

Commit

Permalink
fix: store notifications from simple results (#1591)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasJ authored Nov 20, 2024
1 parent 7a8d62d commit cac6397
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/ash/actions/create/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,17 @@ defmodule Ash.Actions.Create.Bulk do
})
]

{:ok, result, notifications} ->
Process.put({:any_success?, ref}, true)

store_notification(ref, notifications, opts)

[
Ash.Resource.set_metadata(result, %{
bulk_create_index: changeset.context.bulk_create.index
})
]

{:error, error} ->
store_error(ref, error, opts)
[]
Expand All @@ -498,6 +509,7 @@ defmodule Ash.Actions.Create.Bulk do
Ash.DataLayer.transaction(
List.wrap(resource) ++ action.touches_resources,
fn ->
# TODO: check the difference bewteen ref handeling here and in bulk_update
tmp_ref = make_ref()

result =
Expand Down
18 changes: 18 additions & 0 deletions lib/ash/actions/destroy/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1385,6 +1385,24 @@ defmodule Ash.Actions.Destroy.Bulk do
})
]

{:ok, notifications} ->
Process.put({:any_success?, ref}, true)

store_notification(ref, notifications, opts)

[]

{:ok, result, notifications} ->
Process.put({:any_success?, ref}, true)

store_notification(ref, notifications, opts)

[
Ash.Resource.set_metadata(result, %{
bulk_destroy_index: changeset.context.bulk_destroy.index
})
]

{:error, error} ->
store_error(ref, error, opts)
[]
Expand Down
11 changes: 11 additions & 0 deletions lib/ash/actions/update/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,17 @@ defmodule Ash.Actions.Update.Bulk do
})
]

{:ok, result, notifications} ->
Process.put({:any_success?, ref}, true)

store_notification(ref, notifications, opts)

[
Ash.Resource.set_metadata(result, %{
metadata_key => changeset.context |> Map.get(context_key) |> Map.get(:index)
})
]

{:error, error} ->
store_error(ref, error, opts)
[]
Expand Down

0 comments on commit cac6397

Please sign in to comment.