mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-09 09:52:13 +00:00
Remove updating reply count for embeded objects
This commit is contained in:
parent
ff8d76c670
commit
8e4d950f31
|
@ -257,54 +257,4 @@ defmodule Pleroma.Activity do
|
|||
|> where([s], s.actor == ^actor)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
def increase_replies_count(nil), do: nil
|
||||
|
||||
def increase_replies_count(object_ap_id) do
|
||||
from(a in create_by_object_ap_id(object_ap_id),
|
||||
update: [
|
||||
set: [
|
||||
data:
|
||||
fragment(
|
||||
"""
|
||||
jsonb_set(?, '{object, repliesCount}',
|
||||
(coalesce((?->'object'->>'repliesCount')::int, 0) + 1)::varchar::jsonb, true)
|
||||
""",
|
||||
a.data,
|
||||
a.data
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
|> Repo.update_all([])
|
||||
|> case do
|
||||
{1, [activity]} -> activity
|
||||
_ -> {:error, "Not found"}
|
||||
end
|
||||
end
|
||||
|
||||
def decrease_replies_count(nil), do: nil
|
||||
|
||||
def decrease_replies_count(object_ap_id) do
|
||||
from(a in create_by_object_ap_id(object_ap_id),
|
||||
update: [
|
||||
set: [
|
||||
data:
|
||||
fragment(
|
||||
"""
|
||||
jsonb_set(?, '{object, repliesCount}',
|
||||
(greatest(0, (?->'object'->>'repliesCount')::int - 1))::varchar::jsonb, true)
|
||||
""",
|
||||
a.data,
|
||||
a.data
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
|> Repo.update_all([])
|
||||
|> case do
|
||||
{1, [activity]} -> activity
|
||||
_ -> {:error, "Not found"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -95,7 +95,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
"type" => "Create"
|
||||
}) do
|
||||
if is_public?(object) do
|
||||
Activity.increase_replies_count(reply_ap_id)
|
||||
Object.increase_replies_count(reply_ap_id)
|
||||
end
|
||||
end
|
||||
|
@ -106,7 +105,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
data: %{"inReplyTo" => reply_ap_id} = object
|
||||
}) do
|
||||
if is_public?(object) do
|
||||
Activity.decrease_replies_count(reply_ap_id)
|
||||
Object.decrease_replies_count(reply_ap_id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,18 +28,4 @@ defmodule Pleroma.ActivityTest do
|
|||
|
||||
assert activity == found_activity
|
||||
end
|
||||
|
||||
test "reply count" do
|
||||
%{id: id, data: %{"object" => %{"id" => object_ap_id}}} = activity = insert(:note_activity)
|
||||
|
||||
replies_count = activity.data["object"]["repliesCount"] || 0
|
||||
expected_increase = replies_count + 1
|
||||
Activity.increase_replies_count(object_ap_id)
|
||||
%{data: %{"object" => %{"repliesCount" => actual_increase}}} = Activity.get_by_id(id)
|
||||
assert expected_increase == actual_increase
|
||||
expected_decrease = expected_increase - 1
|
||||
Activity.decrease_replies_count(object_ap_id)
|
||||
%{data: %{"object" => %{"repliesCount" => actual_decrease}}} = Activity.get_by_id(id)
|
||||
assert expected_decrease == actual_decrease
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue