forked from AkkomaGang/akkoma
Merge branch 'bugfix/announce-race-condition' into 'develop'
Announcements: Prevent race condition. See merge request pleroma/pleroma!2423
This commit is contained in:
commit
8addbd948c
2 changed files with 28 additions and 0 deletions
|
@ -438,6 +438,7 @@ def announce(
|
||||||
|
|
||||||
defp do_announce(user, object, activity_id, local, public) do
|
defp do_announce(user, object, activity_id, local, public) do
|
||||||
with true <- is_announceable?(object, user, public),
|
with true <- is_announceable?(object, user, public),
|
||||||
|
object <- Object.get_by_id(object.id),
|
||||||
announce_data <- make_announce_data(user, object, activity_id, public),
|
announce_data <- make_announce_data(user, object, activity_id, public),
|
||||||
{:ok, activity} <- insert(announce_data, local),
|
{:ok, activity} <- insert(announce_data, local),
|
||||||
{:ok, object} <- add_announce_to_object(activity, object),
|
{:ok, object} <- add_announce_to_object(activity, object),
|
||||||
|
|
|
@ -48,6 +48,33 @@ test "favoriting race condition" do
|
||||||
assert object.data["like_count"] == 20
|
assert object.data["like_count"] == 20
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "repeating 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.repeat(activity.id, user)
|
||||||
|
end)
|
||||||
|
|
||||||
|
object = Object.get_by_ap_id(activity.data["object"])
|
||||||
|
assert object.data["announcement_count"] == 10
|
||||||
|
|
||||||
|
users
|
||||||
|
|> Enum.map(fn user ->
|
||||||
|
Task.async(fn ->
|
||||||
|
CommonAPI.repeat(activity.id, user)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|> Enum.map(&Task.await/1)
|
||||||
|
|
||||||
|
object = Object.get_by_ap_id(activity.data["object"])
|
||||||
|
assert object.data["announcement_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