mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 08:36:29 +00:00
Merge branch 'bugfix/1629-fav-race-condition' into 'develop'
SideEffects: Run in transaction. Closes #1629 See merge request pleroma/pleroma!2417
This commit is contained in:
commit
850377a7b8
2 changed files with 36 additions and 4 deletions
|
@ -15,12 +15,17 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
|
||||||
# - Add like to object
|
# - Add like to object
|
||||||
# - Set up notification
|
# - Set up notification
|
||||||
def handle(%{data: %{"type" => "Like"}} = object, meta) do
|
def handle(%{data: %{"type" => "Like"}} = object, meta) do
|
||||||
liked_object = Object.get_by_ap_id(object.data["object"])
|
{:ok, result} =
|
||||||
Utils.add_like_to_object(object, liked_object)
|
Pleroma.Repo.transaction(fn ->
|
||||||
|
liked_object = Object.get_by_ap_id(object.data["object"])
|
||||||
|
Utils.add_like_to_object(object, liked_object)
|
||||||
|
|
||||||
Notification.create_notifications(object)
|
Notification.create_notifications(object)
|
||||||
|
|
||||||
{:ok, object, meta}
|
{:ok, object, meta}
|
||||||
|
end)
|
||||||
|
|
||||||
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
# Nothing to do
|
# Nothing to do
|
||||||
|
|
|
@ -21,6 +21,33 @@ defmodule Pleroma.Web.CommonAPITest do
|
||||||
setup do: clear_config([:instance, :limit])
|
setup do: clear_config([:instance, :limit])
|
||||||
setup do: clear_config([:instance, :max_pinned_statuses])
|
setup do: clear_config([:instance, :max_pinned_statuses])
|
||||||
|
|
||||||
|
test "favoriting race condition" do
|
||||||
|
user = insert(:user)
|
||||||
|
users_serial = insert_list(10, :user)
|
||||||
|
users = insert_list(10, :user)
|
||||||
|
|
||||||
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "."})
|
||||||
|
|
||||||
|
users_serial
|
||||||
|
|> Enum.map(fn user ->
|
||||||
|
CommonAPI.favorite(user, activity.id)
|
||||||
|
end)
|
||||||
|
|
||||||
|
object = Object.get_by_ap_id(activity.data["object"])
|
||||||
|
assert object.data["like_count"] == 10
|
||||||
|
|
||||||
|
users
|
||||||
|
|> Enum.map(fn user ->
|
||||||
|
Task.async(fn ->
|
||||||
|
CommonAPI.favorite(user, activity.id)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|> Enum.map(&Task.await/1)
|
||||||
|
|
||||||
|
object = Object.get_by_ap_id(activity.data["object"])
|
||||||
|
assert object.data["like_count"] == 20
|
||||||
|
end
|
||||||
|
|
||||||
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
|
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
|
{:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
|
||||||
|
|
Loading…
Reference in a new issue