update notification id immediately during merge transaction in case spawn off fails (fixes philomena-dev/philomena#70)

This commit is contained in:
byte[] 2020-11-30 23:46:33 -05:00
parent 8bda69b22c
commit ad1963e57c

View file

@ -18,6 +18,7 @@ defmodule Philomena.Images do
alias Philomena.Images.ElasticsearchIndex, as: ImageIndex alias Philomena.Images.ElasticsearchIndex, as: ImageIndex
alias Philomena.ImageFeatures.ImageFeature alias Philomena.ImageFeatures.ImageFeature
alias Philomena.SourceChanges.SourceChange alias Philomena.SourceChanges.SourceChange
alias Philomena.Notifications.Notification
alias Philomena.TagChanges.TagChange alias Philomena.TagChanges.TagChange
alias Philomena.Tags alias Philomena.Tags
alias Philomena.UserStatistics alias Philomena.UserStatistics
@ -728,7 +729,12 @@ defmodule Philomena.Images do
|> select([s], %{image_id: type(^target.id, :integer), user_id: s.user_id}) |> select([s], %{image_id: type(^target.id, :integer), user_id: s.user_id})
|> Repo.all() |> Repo.all()
{count, nil} = Repo.insert_all(Subscription, subscriptions, on_conflict: :nothing) Repo.insert_all(Subscription, subscriptions, on_conflict: :nothing)
{count, nil} =
Notification
|> where(actor_type: "Image", actor_id: ^source.id)
|> Repo.update_all(set: [actor_id: target.id])
{:ok, count} {:ok, count}
end end