WIP: Add backfilling of posts #846
2 changed files with 12 additions and 15 deletions
|
@ -2774,7 +2774,7 @@ def accepts_direct_messages?(%User{accepts_direct_messages_from: :nobody}, _),
|
||||||
do: false
|
do: false
|
||||||
|
|
||||||
def outbox_refreshed(%User{} = user) do
|
def outbox_refreshed(%User{} = user) do
|
||||||
#now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
|
# now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
|
||||||
|
|
||||||
user
|
user
|
||||||
|> cast(%{last_outbox_fetch: NaiveDateTime.utc_now()}, [:last_outbox_fetch])
|
|> cast(%{last_outbox_fetch: NaiveDateTime.utc_now()}, [:last_outbox_fetch])
|
||||||
|
|
|
@ -1858,21 +1858,19 @@ def enqueue_pin_fetches(%{pinned_objects: pins}) do
|
||||||
|
|
||||||
def enqueue_pin_fetches(_), do: nil
|
def enqueue_pin_fetches(_), do: nil
|
||||||
|
|
||||||
|
defp need_outbox_refresh?(last_fetch)
|
||||||
|
|
||||||
|
defp need_outbox_refresh?(nil), do: true
|
||||||
|
|
||||||
|
defp need_outbox_refresh?(%NaiveDateTime{} = last_fetch) do
|
||||||
|
NaiveDateTime.diff(NaiveDateTime.utc_now(), last_fetch) >
|
||||||
|
Config.get!([:activitypub, :outbox_refetch_cooldown])
|
||||||
|
end
|
||||||
|
|
||||||
def enqueue_outbox_fetches(
|
def enqueue_outbox_fetches(
|
||||||
%{outbox: outbox_address, last_outbox_fetch: last_fetch, local: false} = user
|
%{outbox: outbox_address, last_outbox_fetch: last_fetch, local: false} = user
|
||||||
) do
|
) do
|
||||||
with(
|
if need_outbox_refresh?(last_fetch) do
|
||||||
last_fetch <-
|
|
||||||
if last_fetch == nil do
|
|
||||||
0
|
|
||||||
else
|
|
||||||
last_fetch
|
|
||||||
end,
|
|
||||||
now <-
|
|
||||||
NaiveDateTime.utc_now(),
|
|
||||||
{true} <-
|
|
||||||
{last_fetch < NaiveDateTime.add(now, -60)}
|
|
||||||
) 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}")
|
||||||
|
|
||||||
|
@ -1884,8 +1882,7 @@ def enqueue_outbox_fetches(
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
else
|
else
|
||||||
_ ->
|
Logger.debug("Not refetching outbox (TTL not reached)")
|
||||||
Logger.debug("Not refetching outbox (it was fetched <1 min ago)")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
:ok
|
:ok
|
||||||
|
|
Loading…
Reference in a new issue