forked from AkkomaGang/akkoma
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 @@ def handle(object, meta \\ [])
|
|||
# - Add like to object
|
||||
# - Set up notification
|
||||
def handle(%{data: %{"type" => "Like"}} = object, meta) do
|
||||
{:ok, result} =
|
||||
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)
|
||||
|
||||
{:ok, object, meta}
|
||||
end)
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
# Nothing to do
|
||||
|
|
|
@ -21,6 +21,33 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
setup do: clear_config([:instance, :limit])
|
||||
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
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
|
||||
|
|
Loading…
Reference in a new issue