mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-22 16:16:34 +00:00
Merge branch 'oban/user-refresh' into 'develop'
Refactor the async user refreshing to use Oban See merge request pleroma/pleroma!4149
This commit is contained in:
commit
3c1db78a6e
5 changed files with 24 additions and 10 deletions
0
changelog.d/user-refresh-rework.skip
Normal file
0
changelog.d/user-refresh-rework.skip
Normal file
|
@ -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.Web.RichMedia.Backfill, provider: Pleroma.Web.RichMedia.Backfill
|
||||||
|
|
||||||
config :pleroma, Pleroma.User, sync_refreshing: true
|
|
||||||
|
|
||||||
if File.exists?("./config/test.secret.exs") do
|
if File.exists?("./config/test.secret.exs") do
|
||||||
import_config "test.secret.exs"
|
import_config "test.secret.exs"
|
||||||
else
|
else
|
||||||
|
|
|
@ -38,6 +38,7 @@ defmodule Pleroma.User do
|
||||||
alias Pleroma.Web.OAuth
|
alias Pleroma.Web.OAuth
|
||||||
alias Pleroma.Web.RelMe
|
alias Pleroma.Web.RelMe
|
||||||
alias Pleroma.Workers.BackgroundWorker
|
alias Pleroma.Workers.BackgroundWorker
|
||||||
|
alias Pleroma.Workers.UserRefreshWorker
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
require Pleroma.Constants
|
require Pleroma.Constants
|
||||||
|
@ -2165,12 +2166,9 @@ defmodule Pleroma.User do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_refresh(user) do
|
defp maybe_refresh(user) do
|
||||||
fun = fn -> needs_update?(user) && fetch_by_ap_id(user.ap_id) end
|
if needs_update?(user) do
|
||||||
|
UserRefreshWorker.new(%{"ap_id" => user.ap_id})
|
||||||
if Config.get([__MODULE__, :sync_refreshing], false) do
|
|> Oban.insert()
|
||||||
fun.()
|
|
||||||
else
|
|
||||||
Task.start(fun)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
14
lib/pleroma/workers/user_refresh_worker.ex
Normal file
14
lib/pleroma/workers/user_refresh_worker.ex
Normal file
|
@ -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
|
|
@ -953,8 +953,12 @@ defmodule Pleroma.UserTest do
|
||||||
|
|
||||||
{:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
{:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
||||||
|
|
||||||
# User was updated async, fetch from cache now
|
# Oban job was generated to refresh the stale user
|
||||||
updated_user = User.get_cached_by_ap_id(user.ap_id)
|
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
|
assert updated_user.inbox
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue