Activity.Search: fallback on status resolution on DB Timeout
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Thu, 12 Aug 2021 08:29:53 +0000 (10:29 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Fri, 13 Aug 2021 15:57:50 +0000 (17:57 +0200)
Backport of: https://git.pleroma.social/pleroma/pleroma/-/merge_requests/3507

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

index 6cdb665d168b2c6cc437befe4556828a11729336..369a8bbdd857796aa031a35143203ec2a00182f8 100644 (file)
@@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - TwitterAPI: Make `change_password` and `change_email` require params on body instead of query
 - Subscription(Bell) Notifications: Don't create from Pipeline Ingested replies
 - AdminAPI: Fix rendering reports containing a `nil` object
+- Mastodon API: Activity Search fallbacks on status fetching after a DB Timeout/Error
 
 ## 2.4.0 - 2021-08-08
 
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