X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fworkers%2Fpurge_expired_activity.ex;h=027171c1e66fbf7b61eb746b6ba975405f890699;hb=8246db2a968943a0cab615b8b5c1439aa4cb2547;hp=c70587b47f041f02baf8a81e9cbd8b16d2c02046;hpb=93e1c8df9dca697e7bdb822a8a5b3848b7870f53;p=akkoma
diff --git a/lib/pleroma/workers/purge_expired_activity.ex b/lib/pleroma/workers/purge_expired_activity.ex
index c70587b47..027171c1e 100644
--- a/lib/pleroma/workers/purge_expired_activity.ex
+++ b/lib/pleroma/workers/purge_expired_activity.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.PurgeExpiredActivity do
@@ -7,7 +7,7 @@ defmodule Pleroma.Workers.PurgeExpiredActivity do
Worker which purges expired activity.
"""
- use Oban.Worker, queue: :activity_expiration, max_attempts: 1
+ use Oban.Worker, queue: :activity_expiration, max_attempts: 1, unique: [period: :infinity]
import Ecto.Query
@@ -18,12 +18,11 @@ defmodule Pleroma.Workers.PurgeExpiredActivity do
| {:error, :expired_activities_disabled}
| {:error, :expiration_too_close}
def enqueue(args) do
- with true <- enabled?(),
- args when is_map(args) <- validate_expires_at(args) do
+ with true <- enabled?() do
{scheduled_at, args} = Map.pop(args, :expires_at)
args
- |> __MODULE__.new(scheduled_at: scheduled_at)
+ |> new(scheduled_at: scheduled_at)
|> Oban.insert()
end
end
@@ -31,18 +30,8 @@ defmodule Pleroma.Workers.PurgeExpiredActivity do
@impl true
def perform(%Oban.Job{args: %{"activity_id" => id}}) do
with %Activity{} = activity <- find_activity(id),
- %Pleroma.User{} = user <- find_user(activity.object.data["actor"]),
- false <- pinned_by_actor?(activity, user) do
+ %Pleroma.User{} = user <- find_user(activity.object.data["actor"]) do
Pleroma.Web.CommonAPI.delete(activity.id, user)
- else
- :pinned_by_actor ->
- # if activity is pinned, schedule deletion on next day
- enqueue(%{activity_id: id, expires_at: DateTime.add(DateTime.utc_now(), 24 * 3600)})
-
- :ok
-
- error ->
- error
end
end
@@ -52,16 +41,6 @@ defmodule Pleroma.Workers.PurgeExpiredActivity do
end
end
- defp validate_expires_at(%{validate: false} = args), do: Map.delete(args, :validate)
-
- defp validate_expires_at(args) do
- if expires_late_enough?(args[:expires_at]) do
- args
- else
- {:error, :expiration_too_close}
- end
- end
-
defp find_activity(id) do
with nil <- Activity.get_by_id_with_object(id) do
{:error, :activity_not_found}
@@ -74,12 +53,6 @@ defmodule Pleroma.Workers.PurgeExpiredActivity do
end
end
- defp pinned_by_actor?(activity, user) do
- with true <- Activity.pinned_by_actor?(activity, user) do
- :pinned_by_actor
- end
- end
-
def get_expiration(id) do
from(j in Oban.Job,
where: j.state == "scheduled",
@@ -93,6 +66,7 @@ defmodule Pleroma.Workers.PurgeExpiredActivity do
def expires_late_enough?(scheduled_at) do
now = DateTime.utc_now()
diff = DateTime.diff(scheduled_at, now, :millisecond)
- diff > :timer.hours(1)
+ min_lifetime = Pleroma.Config.get([__MODULE__, :min_lifetime], 600)
+ diff > :timer.seconds(min_lifetime)
end
end