aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfeld <feld@feld.me>2021-02-02 17:22:23 +0000
committerfeld <feld@feld.me>2021-02-02 17:22:23 +0000
commit6a2d3fb9a3775fc0e167c71bb8a8fba3608b2f17 (patch)
tree83a3e4164997001d9910750cb23e1c7fca941172
parentb36891d1e6f5d4b0874ef19c4418a46d580c4701 (diff)
parent22486fb4af49214fb2b0eff09f00006fbfdd9745 (diff)
downloadpleroma-6a2d3fb9a3775fc0e167c71bb8a8fba3608b2f17.tar.gz
Merge branch 'fix/2473-purge-expired-activities-duplicates' into 'develop'
fix and delete purge activities duplicates Closes #2473 See merge request pleroma/pleroma!3285
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/pleroma/workers/purge_expired_activity.ex2
-rw-r--r--priv/repo/migrations/20210128092834_remove_duplicates_from_activity_expiration_queue.exs29
3 files changed, 31 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0a24a6a97..f4f3bddb7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -60,6 +60,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Creating incorrect IPv4 address-style HTTP links when encountering certain numbers.
- Reblog API Endpoint: Do not set visibility parameter to public by default and let CommonAPI to infer it from status, so a user can reblog their private status without explicitly setting reblog visibility to private.
- Tag URLs in statuses are now absolute
+- Removed duplicate jobs to purge expired activities
<details>
<summary>API Changes</summary>
diff --git a/lib/pleroma/workers/purge_expired_activity.ex b/lib/pleroma/workers/purge_expired_activity.ex
index 01256831b..027171c1e 100644
--- a/lib/pleroma/workers/purge_expired_activity.ex
+++ b/lib/pleroma/workers/purge_expired_activity.ex
@@ -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
diff --git a/priv/repo/migrations/20210128092834_remove_duplicates_from_activity_expiration_queue.exs b/priv/repo/migrations/20210128092834_remove_duplicates_from_activity_expiration_queue.exs
new file mode 100644
index 000000000..309009205
--- /dev/null
+++ b/priv/repo/migrations/20210128092834_remove_duplicates_from_activity_expiration_queue.exs
@@ -0,0 +1,29 @@
+defmodule Pleroma.Repo.Migrations.RemoveDuplicatesFromActivityExpirationQueue do
+ use Ecto.Migration
+
+ import Ecto.Query, only: [from: 2]
+
+ def up do
+ duplicate_ids =
+ from(j in Oban.Job,
+ where: j.queue == "activity_expiration",
+ where: j.worker == "Pleroma.Workers.PurgeExpiredActivity",
+ where: j.state == "scheduled",
+ select:
+ {fragment("(?)->>'activity_id'", j.args), fragment("array_agg(?)", j.id), count(j.id)},
+ group_by: fragment("(?)->>'activity_id'", j.args),
+ having: count(j.id) > 1
+ )
+ |> Pleroma.Repo.all()
+ |> Enum.map(fn {_, ids, _} ->
+ max_id = Enum.max(ids)
+ List.delete(ids, max_id)
+ end)
+ |> List.flatten()
+
+ from(j in Oban.Job, where: j.id in ^duplicate_ids)
+ |> Pleroma.Repo.delete_all()
+ end
+
+ def down, do: :noop
+end