mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-01 03:46:44 +01:00
Use insert_all instead of update_all for conflict resolution during merges
This commit is contained in:
parent
91e1af6402
commit
0891fe31af
1 changed files with 29 additions and 6 deletions
|
@ -906,15 +906,38 @@ defmodule Philomena.Images do
|
||||||
|
|
||||||
Repo.insert_all(Subscription, subscriptions, on_conflict: :nothing)
|
Repo.insert_all(Subscription, subscriptions, on_conflict: :nothing)
|
||||||
|
|
||||||
|
comment_notifications =
|
||||||
|
from cn in ImageCommentNotification,
|
||||||
|
where: cn.image_id == ^source.id,
|
||||||
|
select: %{
|
||||||
|
user_id: cn.user_id,
|
||||||
|
image_id: ^target.id,
|
||||||
|
comment_id: cn.comment_id,
|
||||||
|
read: cn.read,
|
||||||
|
created_at: cn.created_at,
|
||||||
|
updated_at: cn.updated_at
|
||||||
|
}
|
||||||
|
|
||||||
|
merge_notifications =
|
||||||
|
from mn in ImageMergeNotification,
|
||||||
|
where: mn.target_id == ^source.id,
|
||||||
|
select: %{
|
||||||
|
user_id: mn.user_id,
|
||||||
|
target_id: ^target.id,
|
||||||
|
source_id: mn.source_id,
|
||||||
|
read: mn.read,
|
||||||
|
created_at: mn.created_at,
|
||||||
|
updated_at: mn.updated_at
|
||||||
|
}
|
||||||
|
|
||||||
{comment_notification_count, nil} =
|
{comment_notification_count, nil} =
|
||||||
ImageCommentNotification
|
Repo.insert_all(ImageCommentNotification, comment_notifications, on_conflict: :nothing)
|
||||||
|> where(image_id: ^source.id)
|
|
||||||
|> Repo.update_all(set: [image_id: target.id])
|
|
||||||
|
|
||||||
{merge_notification_count, nil} =
|
{merge_notification_count, nil} =
|
||||||
ImageMergeNotification
|
Repo.insert_all(ImageMergeNotification, merge_notifications, on_conflict: :nothing)
|
||||||
|> where(target_id: ^source.id)
|
|
||||||
|> Repo.update_all(set: [target_id: target.id])
|
Repo.delete_all(exclude(comment_notifications, :select))
|
||||||
|
Repo.delete_all(exclude(merge_notifications, :select))
|
||||||
|
|
||||||
{:ok, {comment_notification_count, merge_notification_count}}
|
{:ok, {comment_notification_count, merge_notification_count}}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue