forked from AkkomaGang/akkoma
Prune old Update activities
Once processed they serve no purpose anymore afaict. Therefor, lets prune them like other transient activities to not unnecessarily bloat the table.
This commit is contained in:
parent
1ef8b967d2
commit
1a7839eaf2
4 changed files with 95 additions and 4 deletions
|
@ -26,6 +26,15 @@ def prune_undos do
|
||||||
|> Repo.delete_all(timeout: :infinity)
|
|> Repo.delete_all(timeout: :infinity)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prune_updates do
|
||||||
|
before_time = cutoff()
|
||||||
|
|
||||||
|
from(a in Activity,
|
||||||
|
where: fragment("?->>'type' = ?", a.data, "Update") and a.inserted_at < ^before_time
|
||||||
|
)
|
||||||
|
|> Repo.delete_all(timeout: :infinity)
|
||||||
|
end
|
||||||
|
|
||||||
def prune_removes do
|
def prune_removes do
|
||||||
before_time = cutoff()
|
before_time = cutoff()
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@ def perform(_job) do
|
||||||
Logger.info("Pruning old undos")
|
Logger.info("Pruning old undos")
|
||||||
ActivityPruner.prune_undos()
|
ActivityPruner.prune_undos()
|
||||||
|
|
||||||
|
Logger.info("Pruning old updates")
|
||||||
|
ActivityPruner.prune_updates()
|
||||||
|
|
||||||
Logger.info("Pruning old removes")
|
Logger.info("Pruning old removes")
|
||||||
ActivityPruner.prune_removes()
|
ActivityPruner.prune_removes()
|
||||||
|
|
||||||
|
|
|
@ -6,22 +6,52 @@ defmodule Pleroma.Activity.PrunerTest do
|
||||||
|
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
|
|
||||||
describe "prune_deletes" do
|
describe "prune_transient_activities" do
|
||||||
test "it prunes old delete objects" do
|
test "it prunes old transient activities" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
old_time = DateTime.utc_now() |> DateTime.add(-31 * 24, :hour)
|
||||||
|
|
||||||
new_delete = insert(:delete_activity, type: "Delete", user: user)
|
new_delete = insert(:delete_activity, type: "Delete", user: user)
|
||||||
|
|
||||||
old_delete =
|
old_delete =
|
||||||
insert(:delete_activity,
|
insert(:delete_activity,
|
||||||
type: "Delete",
|
|
||||||
user: user,
|
user: user,
|
||||||
inserted_at: DateTime.utc_now() |> DateTime.add(-31 * 24, :hour)
|
inserted_at: old_time
|
||||||
)
|
)
|
||||||
|
|
||||||
|
new_update = insert(:update_activity, type: "Update", user: user)
|
||||||
|
|
||||||
|
old_update =
|
||||||
|
insert(:update_activity,
|
||||||
|
type: "Update",
|
||||||
|
user: user,
|
||||||
|
inserted_at: old_time
|
||||||
|
)
|
||||||
|
|
||||||
|
new_undo = insert(:undo_activity)
|
||||||
|
|
||||||
|
old_undo = insert(:undo_activity, inserted_at: old_time)
|
||||||
|
|
||||||
|
new_remove = insert(:remove_activity)
|
||||||
|
|
||||||
|
old_remove = insert(:remove_activity, inserted_at: old_time)
|
||||||
|
|
||||||
Pruner.prune_deletes()
|
Pruner.prune_deletes()
|
||||||
|
Pruner.prune_updates()
|
||||||
|
Pruner.prune_undos()
|
||||||
|
Pruner.prune_removes()
|
||||||
|
|
||||||
assert Activity.get_by_id(new_delete.id)
|
assert Activity.get_by_id(new_delete.id)
|
||||||
refute Activity.get_by_id(old_delete.id)
|
refute Activity.get_by_id(old_delete.id)
|
||||||
|
|
||||||
|
assert Activity.get_by_id(new_update.id)
|
||||||
|
refute Activity.get_by_id(old_update.id)
|
||||||
|
|
||||||
|
assert Activity.get_by_id(new_undo.id)
|
||||||
|
refute Activity.get_by_id(old_undo.id)
|
||||||
|
|
||||||
|
assert Activity.get_by_id(new_remove.id)
|
||||||
|
refute Activity.get_by_id(old_remove.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Factory do
|
||||||
|
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.ActivityPub.UserView
|
||||||
|
|
||||||
@rsa_keys [
|
@rsa_keys [
|
||||||
"test/fixtures/rsa_keys/key_1.pem",
|
"test/fixtures/rsa_keys/key_1.pem",
|
||||||
|
@ -554,6 +555,54 @@ def delete_activity_factory(attrs \\ %{}) do
|
||||||
|> Map.merge(attrs)
|
|> Map.merge(attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def undo_activity_factory(attrs \\ %{}) do
|
||||||
|
like_activity = attrs[:like_activity] || insert(:like_activity)
|
||||||
|
attrs = Map.drop(attrs, [:like_activity])
|
||||||
|
|
||||||
|
data =
|
||||||
|
%{
|
||||||
|
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||||
|
"type" => "Undo",
|
||||||
|
"actor" => like_activity.data["actor"],
|
||||||
|
"to" => like_activity.data["to"],
|
||||||
|
"object" => like_activity.data["id"],
|
||||||
|
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||||
|
"context" => like_activity.data["context"]
|
||||||
|
}
|
||||||
|
|
||||||
|
%Pleroma.Activity{
|
||||||
|
data: data,
|
||||||
|
actor: data["actor"],
|
||||||
|
recipients: data["to"]
|
||||||
|
}
|
||||||
|
|> Map.merge(attrs)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_activity_factory(attrs \\ %{}) do
|
||||||
|
user = attrs[:user] || insert(:user, nickname: "testuser")
|
||||||
|
attrs = Map.drop(attrs, [:user])
|
||||||
|
|
||||||
|
user_data =
|
||||||
|
UserView.render("user.json", %{user: user})
|
||||||
|
|> Map.merge(%{"name" => "new display name"})
|
||||||
|
|
||||||
|
data = %{
|
||||||
|
"type" => "Update",
|
||||||
|
"to" => [
|
||||||
|
user_data["followers"],
|
||||||
|
"https://www.w3.org/ns/activitystreams#Public"
|
||||||
|
],
|
||||||
|
"actor" => user_data["id"],
|
||||||
|
"object" => user_data
|
||||||
|
}
|
||||||
|
|
||||||
|
%Pleroma.Activity{
|
||||||
|
actor: user_data["id"],
|
||||||
|
data: data
|
||||||
|
}
|
||||||
|
|> Map.merge(attrs)
|
||||||
|
end
|
||||||
|
|
||||||
def oauth_app_factory do
|
def oauth_app_factory do
|
||||||
%Pleroma.Web.OAuth.App{
|
%Pleroma.Web.OAuth.App{
|
||||||
client_name: sequence(:client_name, &"Some client #{&1}"),
|
client_name: sequence(:client_name, &"Some client #{&1}"),
|
||||||
|
|
Loading…
Reference in a new issue