forked from AkkomaGang/akkoma
reimplement outbox fetching timeout
This commit is contained in:
parent
6d9fda9a24
commit
117a63172f
4 changed files with 20 additions and 33 deletions
|
@ -164,7 +164,8 @@ defp cachex_children do
|
|||
build_cachex("request_signatures", default_ttl: :timer.hours(24 * 30), limit: 3000),
|
||||
build_cachex("rel_me", default_ttl: :timer.hours(24 * 30), limit: 300),
|
||||
build_cachex("host_meta", default_ttl: :timer.minutes(120), limit: 5000),
|
||||
build_cachex("http_backoff", default_ttl: :timer.hours(24 * 30), limit: 10000)
|
||||
build_cachex("http_backoff", default_ttl: :timer.hours(24 * 30), limit: 10000),
|
||||
build_cachex("backfetch_timer", default_ttl: :timer.hours(24 * 30), limit: 10000)
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -153,7 +153,6 @@ defmodule Pleroma.User do
|
|||
field(:inbox, :string)
|
||||
field(:shared_inbox, :string)
|
||||
field(:outbox, :string, default: nil)
|
||||
field(:last_outbox_fetch, :naive_datetime, default: nil)
|
||||
field(:last_active_at, :naive_datetime)
|
||||
field(:disclose_client, :boolean, default: true)
|
||||
field(:pinned_objects, :map, default: %{})
|
||||
|
@ -2772,12 +2771,4 @@ def accepts_direct_messages?(%User{accepts_direct_messages_from: :everybody}, _)
|
|||
|
||||
def accepts_direct_messages?(%User{accepts_direct_messages_from: :nobody}, _),
|
||||
do: false
|
||||
|
||||
def outbox_refreshed(%User{} = user) do
|
||||
# now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
|
||||
|
||||
user
|
||||
|> cast(%{last_outbox_fetch: NaiveDateTime.utc_now()}, [:last_outbox_fetch])
|
||||
|> update_and_set_cache()
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1858,31 +1858,28 @@ def enqueue_pin_fetches(%{pinned_objects: pins}) do
|
|||
|
||||
def enqueue_pin_fetches(_), do: nil
|
||||
|
||||
defp need_outbox_refresh?(last_fetch)
|
||||
@cachex Pleroma.Config.get([:cachex, :provider], Cachex)
|
||||
@timer :backfetch_timer_cache
|
||||
|
||||
defp need_outbox_refresh?(nil), do: true
|
||||
def enqueue_outbox_fetches(%{outbox: outbox_address, local: false}) do
|
||||
case @cachex.get(@timer, outbox_address) do
|
||||
{:ok, nil} ->
|
||||
@cachex.put(
|
||||
@timer,
|
||||
outbox_address,
|
||||
true,
|
||||
ttl: Config.get!([:activitypub, :outbox_refetch_cooldown])
|
||||
)
|
||||
|
||||
defp need_outbox_refresh?(%NaiveDateTime{} = last_fetch) do
|
||||
NaiveDateTime.diff(NaiveDateTime.utc_now(), last_fetch) >
|
||||
Config.get!([:activitypub, :outbox_refetch_cooldown])
|
||||
end
|
||||
# enqueue a task to fetch the outbox
|
||||
Logger.debug("Refetching outbox #{outbox_address}")
|
||||
|
||||
def enqueue_outbox_fetches(
|
||||
%{outbox: outbox_address, last_outbox_fetch: last_fetch, local: false} = user
|
||||
) do
|
||||
if need_outbox_refresh?(last_fetch) do
|
||||
# enqueue a task to fetch the outbox
|
||||
Logger.debug("Refetching outbox #{outbox_address}")
|
||||
Pleroma.Workers.RemoteFetcherWorker.enqueue("fetch_outbox", %{
|
||||
"id" => outbox_address
|
||||
})
|
||||
|
||||
Pleroma.Workers.RemoteFetcherWorker.enqueue("fetch_outbox", %{
|
||||
"id" => outbox_address
|
||||
})
|
||||
|
||||
User.outbox_refreshed(user)
|
||||
|
||||
:ok
|
||||
else
|
||||
Logger.debug("Not refetching outbox (TTL not reached: #{last_fetch}, age #{NaiveDateTime.diff(NaiveDateTime.utc_now(), last_fetch)})")
|
||||
a ->
|
||||
Logger.debug("Not refetching outbox (TTL not reached)")
|
||||
end
|
||||
|
||||
:ok
|
||||
|
|
|
@ -4,14 +4,12 @@ defmodule Pleroma.Repo.Migrations.UsersAddOutboxes do
|
|||
def up do
|
||||
alter table(:users) do
|
||||
add_if_not_exists(:outbox, :text)
|
||||
add_if_not_exists(:last_outbox_fetch, :naive_datetime)
|
||||
end
|
||||
end
|
||||
|
||||
def down do
|
||||
alter table(:users) do
|
||||
remove_if_exists(:outbox, :text)
|
||||
remove_if_exists(:last_outbox_fetch, :naive_datetime)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue