Remove updating reply count for embeded objects
This commit is contained in:
parent
ff8d76c670
commit
8e4d950f31
|
@ -257,54 +257,4 @@ def all_by_actor_and_id(actor, status_ids) do
|
||||||
|> where([s], s.actor == ^actor)
|
|> where([s], s.actor == ^actor)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -95,7 +95,6 @@ def increase_replies_count_if_reply(%{
|
||||||
"type" => "Create"
|
"type" => "Create"
|
||||||
}) do
|
}) do
|
||||||
if is_public?(object) do
|
if is_public?(object) do
|
||||||
Activity.increase_replies_count(reply_ap_id)
|
|
||||||
Object.increase_replies_count(reply_ap_id)
|
Object.increase_replies_count(reply_ap_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -106,7 +105,6 @@ def decrease_replies_count_if_reply(%Object{
|
||||||
data: %{"inReplyTo" => reply_ap_id} = object
|
data: %{"inReplyTo" => reply_ap_id} = object
|
||||||
}) do
|
}) do
|
||||||
if is_public?(object) do
|
if is_public?(object) do
|
||||||
Activity.decrease_replies_count(reply_ap_id)
|
|
||||||
Object.decrease_replies_count(reply_ap_id)
|
Object.decrease_replies_count(reply_ap_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,18 +28,4 @@ test "returns the activity that created an object" do
|
||||||
|
|
||||||
assert activity == found_activity
|
assert activity == found_activity
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue