Remove updating reply count for embeded objects
authorrinpatch <rinpatch@sdf.org>
Wed, 17 Apr 2019 12:54:09 +0000 (15:54 +0300)
committerrinpatch <rinpatch@sdf.org>
Wed, 17 Apr 2019 12:54:09 +0000 (15:54 +0300)
lib/pleroma/activity.ex
lib/pleroma/web/activity_pub/activity_pub.ex
test/activity_test.exs

index 99cc9c077cb131472711e3e26a98ad880e0709ee..478d163564bc2a4788d711d600218edbfb8e90b4 100644 (file)
@@ -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
index 1a3b47cb34fe401d707e6c5e4abbb41785f781bc..28fca6116ce2c87e214c5cf29556412708860b00 100644 (file)
@@ -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
index dc9c56a21b1b25efe2145509eb8dee6d83817b16..ad889f544830a5ed8463312461c5ee35bdd3b7af 100644 (file)
@@ -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