From 8e4d950f31ec3ea956f6892f9f36b419344bf930 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Wed, 17 Apr 2019 15:54:09 +0300 Subject: [PATCH] Remove updating reply count for embeded objects --- lib/pleroma/activity.ex | 50 -------------------- lib/pleroma/web/activity_pub/activity_pub.ex | 2 - test/activity_test.exs | 14 ------ 3 files changed, 66 deletions(-) diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 99cc9c077..478d16356 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -257,54 +257,4 @@ def all_by_actor_and_id(actor, status_ids) 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 diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 1a3b47cb3..28fca6116 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -95,7 +95,6 @@ def increase_replies_count_if_reply(%{ "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 @@ def decrease_replies_count_if_reply(%Object{ 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 diff --git a/test/activity_test.exs b/test/activity_test.exs index dc9c56a21..ad889f544 100644 --- a/test/activity_test.exs +++ b/test/activity_test.exs @@ -28,18 +28,4 @@ test "returns the activity that created an object" 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