Merge branch 'bugfix/status-search-fallback' into 'develop'
authorrinpatch <rin@patch.cx>
Fri, 13 Aug 2021 12:09:39 +0000 (12:09 +0000)
committerrinpatch <rin@patch.cx>
Fri, 13 Aug 2021 12:09:39 +0000 (12:09 +0000)
Activity.Search: resolve status on DB Timeout

Closes #2566

See merge request pleroma/pleroma!3507

CHANGELOG.md
lib/pleroma/activity/search.ex

index ca3ae9ac025cbf634b1f546101b2b5f6fef7b40a..231cac990c0c82f38313f0c5bb56aee656472884 100644 (file)
@@ -15,6 +15,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 
 ### Removed
 
+## Unreleased-patch
+- Mastodon API: Activity Search fallbacks on status fetching after a DB Timeout/Error
+
 ## 2.4.0 - 2021-08-xx
 
 ### Changed
index ed898ba4ff847a79c93c15f6d9b6c7355057d50b..a5923519c3d7434534d848534093cd38144c99f1 100644 (file)
@@ -26,19 +26,23 @@ defmodule Pleroma.Activity.Search do
         :plain
       end
 
-    Activity
-    |> Activity.with_preloaded_object()
-    |> Activity.restrict_deactivated_users()
-    |> restrict_public()
-    |> query_with(index_type, search_query, search_function)
-    |> maybe_restrict_local(user)
-    |> maybe_restrict_author(author)
-    |> maybe_restrict_blocked(user)
-    |> Pagination.fetch_paginated(
-      %{"offset" => offset, "limit" => limit, "skip_order" => index_type == :rum},
-      :offset
-    )
-    |> maybe_fetch(user, search_query)
+    try do
+      Activity
+      |> Activity.with_preloaded_object()
+      |> Activity.restrict_deactivated_users()
+      |> restrict_public()
+      |> query_with(index_type, search_query, search_function)
+      |> maybe_restrict_local(user)
+      |> maybe_restrict_author(author)
+      |> maybe_restrict_blocked(user)
+      |> Pagination.fetch_paginated(
+        %{"offset" => offset, "limit" => limit, "skip_order" => index_type == :rum},
+        :offset
+      )
+      |> maybe_fetch(user, search_query)
+    rescue
+      _ -> maybe_fetch([], user, search_query)
+    end
   end
 
   def maybe_restrict_author(query, %User{} = author) do