fix last_outbox_fetch

This commit is contained in:
TudbuT 2024-11-03 23:50:42 +01:00
parent e37ffa1b1f
commit 718dae0f97
No known key found for this signature in database
GPG key ID: B3CF345217F202D3
3 changed files with 8 additions and 11 deletions

View file

@ -2771,9 +2771,11 @@ def accepts_direct_messages?(%User{accepts_direct_messages_from: :everybody}, _)
def accepts_direct_messages?(%User{accepts_direct_messages_from: :nobody}, _), def accepts_direct_messages?(%User{accepts_direct_messages_from: :nobody}, _),
do: false do: false
def outbox_refreshed(user) do def outbox_refreshed(%User{} = user) do
#now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
user user
|> cast(%{last_outbox_fetch: DateTime.utc_now()}, [:last_outbox_fetch]) |> cast(%{last_outbox_fetch: NaiveDateTime.utc_now()}, [:last_outbox_fetch])
|> update_and_set_cache() |> update_and_set_cache()
end end
end end

View file

@ -1867,16 +1867,11 @@ def enqueue_outbox_fetches(
0 0
else else
last_fetch last_fetch
|> DateTime.from_iso8601()
|> DateTime.to_unix()
end, end,
now <- DateTime.utc_now().to_unix(), now <-
# future => epoch stuff, let it pass NaiveDateTime.utc_now(),
# >60 secs in past => ok
# otherwise in timeout
{true} <- {true} <-
{last_fetch > now || {last_fetch < NaiveDateTime.add(now, -60)}
last_fetch < now - 60}
) do ) do
# enqueue a task to fetch the outbox # enqueue a task to fetch the outbox
Logger.debug("Refetching outbox #{outbox_address}") Logger.debug("Refetching outbox #{outbox_address}")

View file

@ -4,7 +4,7 @@ defmodule Pleroma.Repo.Migrations.UsersAddOutboxes do
def up do def up do
alter table(:users) do alter table(:users) do
add_if_not_exists(:outbox, :text) add_if_not_exists(:outbox, :text)
add_if_not_exists(:last_outbox_fetch, :text) add_if_not_exists(:last_outbox_fetch, :naive_datetime)
end end
end end