From ad1963e57c95a5cff57051c5cf9557b991fcab28 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 30 Nov 2020 23:46:33 -0500 Subject: [PATCH] update notification id immediately during merge transaction in case spawn off fails (fixes philomena-dev/philomena#70) --- lib/philomena/images.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/philomena/images.ex b/lib/philomena/images.ex index e7e1141f..64dea399 100644 --- a/lib/philomena/images.ex +++ b/lib/philomena/images.ex @@ -18,6 +18,7 @@ defmodule Philomena.Images do alias Philomena.Images.ElasticsearchIndex, as: ImageIndex alias Philomena.ImageFeatures.ImageFeature alias Philomena.SourceChanges.SourceChange + alias Philomena.Notifications.Notification alias Philomena.TagChanges.TagChange alias Philomena.Tags alias Philomena.UserStatistics @@ -728,7 +729,12 @@ defmodule Philomena.Images do |> select([s], %{image_id: type(^target.id, :integer), user_id: s.user_id}) |> 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} end