diff options
author | Floatingghost <hannah@coffee-and-dreams.uk> | 2024-05-31 09:04:00 -0400 |
---|---|---|
committer | tusooa <tusooa@kazv.moe> | 2024-05-31 09:09:04 -0400 |
commit | 0302431888d457d254f152a502946e6ffe7935e4 (patch) | |
tree | 464b7bf526666abefab18b13ab98e182bc02524e /lib | |
parent | ff6f5a417f1f22d53b1196cc19e1ba9ad6e0ed2c (diff) | |
download | pleroma-0302431888d457d254f152a502946e6ffe7935e4.tar.gz pleroma-0302431888d457d254f152a502946e6ffe7935e4.zip |
Use proper workers for fetching pins instead of an ad-hoc task
BUG: https://git.pleroma.social/pleroma/pleroma/-/issues/3276
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub.ex | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 5bb0fba6e..1247ae7ce 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -1794,24 +1794,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end end - def pinned_fetch_task(nil), do: nil - - def pinned_fetch_task(%{pinned_objects: pins}) do - if Enum.all?(pins, fn {ap_id, _} -> - Object.get_cached_by_ap_id(ap_id) || - match?({:ok, _object}, Fetcher.fetch_object_from_id(ap_id)) - end) do - :ok - else - :error - end + def enqueue_pin_fetches(%{pinned_objects: pins}) do + # enqueue a task to fetch all pinned objects + Enum.each(pins, fn {ap_id, _} -> + if is_nil(Object.get_cached_by_ap_id(ap_id)) do + Pleroma.Workers.RemoteFetcherWorker.enqueue("fetch_remote", %{ + "id" => ap_id, + "depth" => 1 + }) + end + end) end + def enqueue_pin_fetches(_), do: nil + def make_user_from_ap_id(ap_id, additional \\ []) do user = User.get_cached_by_ap_id(ap_id) with {:ok, data} <- fetch_and_prepare_user_from_ap_id(ap_id, additional) do - {:ok, _pid} = Task.start(fn -> pinned_fetch_task(data) end) + enqueue_pin_fetches(data) if user do user |