[#3213] Experimental / debug feature: `database: [improved_hashtag_timeline: :presele...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 18 Feb 2021 18:03:06 +0000 (21:03 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 18 Feb 2021 18:03:06 +0000 (21:03 +0300)
lib/pleroma/web/activity_pub/activity_pub.ex

index e012f2779e9be2820d609f8276c6c004d0b86d2a..5392ce7c9eaba8836c35b5f3554a39d4d9c59003 100644 (file)
@@ -787,19 +787,42 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   end
 
   defp restrict_hashtag_any(query, %{tag: [_ | _] = tags}) do
-    from(
-      [_activity, object] in query,
-      where:
-        fragment(
-          """
-          EXISTS (SELECT 1 FROM hashtags JOIN hashtags_objects
-            ON hashtags_objects.hashtag_id = hashtags.id WHERE hashtags.name = ANY(?::citext[])
-              AND hashtags_objects.object_id = ? LIMIT 1)
-          """,
-          ^tags,
-          object.id
+    # TODO: refactor: debug / experimental feature
+    if Config.get([:database, :improved_hashtag_timeline]) == :preselect_hashtag_ids do
+      hashtag_ids =
+        from(ht in Pleroma.Hashtag,
+          where: fragment("name = ANY(?::citext[])", ^tags),
+          select: ht.id
         )
-    )
+        |> Repo.all()
+
+      from(
+        [_activity, object] in query,
+        where:
+          fragment(
+            """
+            EXISTS (
+            SELECT 1 FROM hashtags_objects WHERE hashtag_id = ANY(?) AND object_id = ? LIMIT 1)
+            """,
+            ^hashtag_ids,
+            object.id
+          )
+      )
+    else
+      from(
+        [_activity, object] in query,
+        where:
+          fragment(
+            """
+            EXISTS (SELECT 1 FROM hashtags JOIN hashtags_objects
+              ON hashtags_objects.hashtag_id = hashtags.id WHERE hashtags.name = ANY(?::citext[])
+                AND hashtags_objects.object_id = ? LIMIT 1)
+            """,
+            ^tags,
+            object.id
+          )
+      )
+    end
   end
 
   defp restrict_hashtag_any(query, %{tag: tag}) when is_binary(tag) do