forked from AkkomaGang/akkoma
prune objects task: use Repo.delete_all()
This commit is contained in:
parent
f446f94290
commit
a023ca004c
1 changed files with 11 additions and 4 deletions
|
@ -5,6 +5,7 @@
|
||||||
defmodule Mix.Tasks.Pleroma.Database do
|
defmodule Mix.Tasks.Pleroma.Database do
|
||||||
alias Mix.Tasks.Pleroma.Common
|
alias Mix.Tasks.Pleroma.Common
|
||||||
alias Pleroma.Conversation
|
alias Pleroma.Conversation
|
||||||
|
alias Pleroma.Object
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
require Logger
|
require Logger
|
||||||
|
@ -78,6 +79,8 @@ def run(["update_users_following_followers_counts"]) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["prune_objects" | args]) do
|
def run(["prune_objects" | args]) do
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
{options, [], []} =
|
{options, [], []} =
|
||||||
OptionParser.parse(
|
OptionParser.parse(
|
||||||
args,
|
args,
|
||||||
|
@ -96,11 +99,15 @@ def run(["prune_objects" | args]) do
|
||||||
NaiveDateTime.utc_now()
|
NaiveDateTime.utc_now()
|
||||||
|> NaiveDateTime.add(-(deadline * 86_400))
|
|> NaiveDateTime.add(-(deadline * 86_400))
|
||||||
|
|
||||||
Repo.query!(
|
public = "https://www.w3.org/ns/activitystreams#Public"
|
||||||
"DELETE FROM objects WHERE inserted_at < $1 AND split_part(data->>'actor', '/', 3) != $2",
|
|
||||||
[time_deadline, Pleroma.Web.Endpoint.host()],
|
from(o in Object,
|
||||||
timeout: :infinity
|
where: fragment("?->'to' \\? ? OR ?->'cc' \\? ?", o.data, ^public, o.data, ^public),
|
||||||
|
where: o.inserted_at < ^time_deadline,
|
||||||
|
where:
|
||||||
|
fragment("split_part(?->>'actor', '/', 3) != ?", o.data, ^Pleroma.Web.Endpoint.host())
|
||||||
)
|
)
|
||||||
|
|> Repo.delete_all()
|
||||||
|
|
||||||
if Keyword.get(options, :vacuum) do
|
if Keyword.get(options, :vacuum) do
|
||||||
Logger.info("Runnning VACUUM FULL")
|
Logger.info("Runnning VACUUM FULL")
|
||||||
|
|
Loading…
Reference in a new issue