replies filtering for blocked domains
authorAlexander Strizhakov <alex.strizhakov@gmail.com>
Tue, 2 Jun 2020 05:50:24 +0000 (08:50 +0300)
committerAlexander Strizhakov <alex.strizhakov@gmail.com>
Tue, 2 Jun 2020 06:00:10 +0000 (09:00 +0300)
benchmarks/load_testing/fetcher.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/api_spec/operations/timeline_operation.ex
lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex
test/web/mastodon_api/controllers/timeline_controller_test.exs

index b278faf9f5985e3c1bcdad9e4d556c615b82a1e2..22a06e472c9a185f17bb3e9f88ce09cbf0d0a2c5 100644 (file)
@@ -228,24 +228,16 @@ defmodule Pleroma.LoadTesting.Fetcher do
     fetch_public_timeline(opts, "public timeline only media")
   end
 
-  # TODO: remove using `:method` after benchmarks
   defp fetch_public_timeline(user, :with_blocks) do
     opts = opts_for_public_timeline(user)
 
     remote_non_friends = Agent.get(:non_friends_remote, & &1)
 
-    Benchee.run(
-      %{
-        "public timeline without blocks" => fn opts ->
-          ActivityPub.fetch_public_activities(opts)
-        end
-      },
-      inputs: %{
-        "old filtering" => Map.delete(opts, :method),
-        "with psql fun" => Map.put(opts, :method, :fun),
-        "with unnest" => Map.put(opts, :method, :unnest)
-      }
-    )
+    Benchee.run(%{
+      "public timeline without blocks" => fn ->
+        ActivityPub.fetch_public_activities(opts)
+      end
+    })
 
     Enum.each(remote_non_friends, fn non_friend ->
       {:ok, _} = User.block(user, non_friend)
@@ -257,15 +249,10 @@ defmodule Pleroma.LoadTesting.Fetcher do
 
     Benchee.run(
       %{
-        "public timeline with user block" => fn opts ->
+        "public timeline with user block" => fn ->
           ActivityPub.fetch_public_activities(opts)
         end
       },
-      inputs: %{
-        "old filtering" => Map.delete(opts, :method),
-        "with psql fun" => Map.put(opts, :method, :fun),
-        "with unnest" => Map.put(opts, :method, :unnest)
-      }
     )
 
     domains =
@@ -289,11 +276,6 @@ defmodule Pleroma.LoadTesting.Fetcher do
         "public timeline with domain block" => fn opts ->
           ActivityPub.fetch_public_activities(opts)
         end
-      },
-      inputs: %{
-        "old filtering" => Map.delete(opts, :method),
-        "with psql fun" => Map.put(opts, :method, :fun),
-        "with unnest" => Map.put(opts, :method, :unnest)
       }
     )
   end
index e7958f7a8c7cbdda4b561d23fa666506ffa7876a..673b10b22125b9fde428e1bfb8a5ff8c750b1ff9 100644 (file)
@@ -932,37 +932,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     query =
       if has_named_binding?(query, :object), do: query, else: Activity.with_joined_object(query)
 
-    # TODO: update after benchmarks
-    query =
-      case opts[:method] do
-        :fun ->
-          from(a in query,
-            where:
-              fragment(
-                "recipients_contain_blocked_domains(?, ?) = false",
-                a.recipients,
-                ^domain_blocks
-              )
-          )
-
-        :unnest ->
-          from(a in query,
-            where:
-              fragment(
-                "NOT ? && (SELECT ARRAY(SELECT split_part(UNNEST(?), '/', 3)))",
-                ^domain_blocks,
-                a.recipients
-              )
-          )
-
-        _ ->
-          query
-      end
-
     from(
       [activity, object: o] in query,
       where: fragment("not (? = ANY(?))", activity.actor, ^blocked_ap_ids),
       where: fragment("not (? && ?)", activity.recipients, ^blocked_ap_ids),
+      where:
+        fragment(
+          "recipients_contain_blocked_domains(?, ?) = false",
+          activity.recipients,
+          ^domain_blocks
+        ),
       where:
         fragment(
           "not (?->>'type' = 'Announce' and ?->'to' \\?| ?)",
index 375b441a1fd1670a2c9402c1f38a73a2cb24ea94..8e19bace7a9285a5a6b18814a0120b72529376be 100644 (file)
@@ -62,13 +62,6 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
         only_media_param(),
         with_muted_param(),
         exclude_visibilities_param(),
-        # TODO: remove after benchmarks
-        Operation.parameter(
-          :method,
-          :query,
-          %Schema{type: :string},
-          "Temp parameter"
-        ),
         reply_visibility_param() | pagination_params()
       ],
       operationId: "TimelineController.public",
index 1734df4b56a9c6db7562134c628a5f61f4dfb7ce..958567510bcc22d26e24c9c8bc456d6e28463476 100644 (file)
@@ -109,23 +109,14 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
     if restrict? and is_nil(user) do
       render_error(conn, :unauthorized, "authorization required for timeline view")
     else
-      # TODO: return back after benchmarks
-      params =
+      activities =
         params
         |> Map.put("type", ["Create", "Announce"])
         |> Map.put("local_only", local_only)
         |> Map.put("blocking_user", user)
         |> Map.put("muting_user", user)
         |> Map.put("reply_filtering_user", user)
-
-      params =
-        if params["method"] do
-          Map.put(params, :method, String.to_existing_atom(params["method"]))
-        else
-          params
-        end
-
-      activities = ActivityPub.fetch_public_activities(params)
+        |> ActivityPub.fetch_public_activities()
 
       conn
       |> add_link_headers(activities, %{"local" => local_only})
index 3474c0cf949ba4b614dcb06c7501ea8f28817311..2ad6828adb16fbb3851ff1f57dbcbf05aca1224f 100644 (file)
@@ -111,7 +111,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
       [%{"id" => ^activity_id}] = json_response_and_validate_schema(res_conn, 200)
     end
 
-    # TODO: update after benchmarks
     test "doesn't return replies if follow is posting with users from blocked domain" do
       %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
       friend = insert(:user)
@@ -129,31 +128,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
       {:ok, _reply_from_friend} =
         CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
 
-      res_conn = get(conn, "/api/v1/timelines/public?method=fun")
-
-      activities = json_response_and_validate_schema(res_conn, 200)
-      [%{"id" => ^activity_id}] = activities
-    end
-
-    # TODO: update after benchmarks
-    test "doesn't return replies if follow is posting with users from blocked domain with unnest param" do
-      %{conn: conn, user: blocker} = oauth_access(["read:statuses"])
-      friend = insert(:user)
-      blockee = insert(:user, ap_id: "https://example.com/users/blocked")
-      {:ok, blocker} = User.follow(blocker, friend)
-      {:ok, blocker} = User.block_domain(blocker, "example.com")
-
-      conn = assign(conn, :user, blocker)
-
-      {:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
-
-      {:ok, reply_from_blockee} =
-        CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
-
-      {:ok, _reply_from_friend} =
-        CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
-
-      res_conn = get(conn, "/api/v1/timelines/public?method=unnest")
+      res_conn = get(conn, "/api/v1/timelines/public")
 
       activities = json_response_and_validate_schema(res_conn, 200)
       [%{"id" => ^activity_id}] = activities