Browse Source

Merge branch 'fix/prune-hashtags' into 'develop'

get prune_objects to work again

See merge request pleroma/pleroma!3397
cycles-validator
feld 3 years ago
parent
commit
b553bfd745
3 changed files with 29 additions and 0 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +9
    -0
      lib/mix/tasks/pleroma/database.ex
  3. +19
    -0
      priv/repo/migrations/20210420204354_delete_hashtags_objects_cascade.exs

+ 1
- 0
CHANGELOG.md View File

@@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed
- Don't crash so hard when email settings are invalid.
- Checking activated Upload Filters for required commands.
- Mix task `pleroma.database prune_objects`

### Removed
- **Breaking**: Remove deprecated `/api/qvitter/statuses/notifications/read` (replaced by `/api/v1/pleroma/notifications/read`)


+ 9
- 0
lib/mix/tasks/pleroma/database.ex View File

@@ -96,6 +96,15 @@ defmodule Mix.Tasks.Pleroma.Database do
)
|> Repo.delete_all(timeout: :infinity)

prune_hashtags_query = """
DELETE FROM hashtags AS ht
WHERE NOT EXISTS (
SELECT 1 FROM hashtags_objects hto
WHERE ht.id = hto.hashtag_id)
"""

Repo.query(prune_hashtags_query)

if Keyword.get(options, :vacuum) do
Maintenance.vacuum("full")
end


+ 19
- 0
priv/repo/migrations/20210420204354_delete_hashtags_objects_cascade.exs View File

@@ -0,0 +1,19 @@
defmodule Pleroma.Repo.Migrations.DeleteHashtagsObjectsCascade do
use Ecto.Migration

def up do
execute("ALTER TABLE hashtags_objects DROP CONSTRAINT hashtags_objects_object_id_fkey")

alter table(:hashtags_objects) do
modify(:object_id, references(:objects, on_delete: :delete_all))
end
end

def down do
execute("ALTER TABLE hashtags_objects DROP CONSTRAINT hashtags_objects_object_id_fkey")

alter table(:hashtags_objects) do
modify(:object_id, references(:objects, on_delete: :nothing))
end
end
end

Loading…
Cancel
Save