logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: 3c1db78a6e8dc3cf9087ba5f825d53d5c6a9856d
parent 825541b27c71d3a9b6f597a9934151831c52f6e5
Author: feld <feld@feld.me>
Date:   Tue, 18 Jun 2024 13:06:11 +0000

Merge branch 'oban/user-refresh' into 'develop'

Refactor the async user refreshing to use Oban

See merge request pleroma/pleroma!4149

Diffstat:

Achangelog.d/user-refresh-rework.skip0
Mconfig/test.exs2--
Mlib/pleroma/user.ex10++++------
Alib/pleroma/workers/user_refresh_worker.ex14++++++++++++++
Mtest/pleroma/user_test.exs8++++++--
5 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/changelog.d/user-refresh-rework.skip b/changelog.d/user-refresh-rework.skip diff --git a/config/test.exs b/config/test.exs @@ -183,8 +183,6 @@ config :pleroma, Pleroma.Emoji.Loader, test_emoji: true config :pleroma, Pleroma.Web.RichMedia.Backfill, provider: Pleroma.Web.RichMedia.Backfill -config :pleroma, Pleroma.User, sync_refreshing: true - if File.exists?("./config/test.secret.exs") do import_config "test.secret.exs" else diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex @@ -38,6 +38,7 @@ defmodule Pleroma.User do alias Pleroma.Web.OAuth alias Pleroma.Web.RelMe alias Pleroma.Workers.BackgroundWorker + alias Pleroma.Workers.UserRefreshWorker require Logger require Pleroma.Constants @@ -2165,12 +2166,9 @@ defmodule Pleroma.User do end defp maybe_refresh(user) do - fun = fn -> needs_update?(user) && fetch_by_ap_id(user.ap_id) end - - if Config.get([__MODULE__, :sync_refreshing], false) do - fun.() - else - Task.start(fun) + if needs_update?(user) do + UserRefreshWorker.new(%{"ap_id" => user.ap_id}) + |> Oban.insert() end end diff --git a/lib/pleroma/workers/user_refresh_worker.ex b/lib/pleroma/workers/user_refresh_worker.ex @@ -0,0 +1,14 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Workers.UserRefreshWorker do + use Pleroma.Workers.WorkerHelper, queue: "background", max_attempts: 1, unique: [period: 300] + + alias Pleroma.User + + @impl Oban.Worker + def perform(%Job{args: %{"ap_id" => ap_id}}) do + User.fetch_by_ap_id(ap_id) + end +end diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs @@ -953,8 +953,12 @@ defmodule Pleroma.UserTest do {:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin") - # User was updated async, fetch from cache now - updated_user = User.get_cached_by_ap_id(user.ap_id) + # Oban job was generated to refresh the stale user + assert_enqueued(worker: "Pleroma.Workers.UserRefreshWorker", args: %{"ap_id" => user.ap_id}) + + # Run job to refresh the user; just capture its output instead of fetching it again + assert {:ok, updated_user} = + perform_job(Pleroma.Workers.UserRefreshWorker, %{"ap_id" => user.ap_id}) assert updated_user.inbox