Merge pull request #7751 from gitlab-mr-iid-4374 into develop
This commit is contained in:
commit
588bc656f2
3 changed files with 41 additions and 1 deletions
1
changelog.d/prune-hashtag-follow-3376.fix
Normal file
1
changelog.d/prune-hashtag-follow-3376.fix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
DB prune: Check if user follows hashtag with no objects before deletion
|
||||||
|
|
@ -226,7 +226,12 @@ defmodule Mix.Tasks.Pleroma.Database do
|
||||||
DELETE FROM hashtags AS ht
|
DELETE FROM hashtags AS ht
|
||||||
WHERE NOT EXISTS (
|
WHERE NOT EXISTS (
|
||||||
SELECT 1 FROM hashtags_objects hto
|
SELECT 1 FROM hashtags_objects hto
|
||||||
WHERE ht.id = hto.hashtag_id)
|
WHERE ht.id = hto.hashtag_id
|
||||||
|
)
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM user_follows_hashtag ufh
|
||||||
|
WHERE ht.id = ufh.hashtag_id
|
||||||
|
)
|
||||||
"""
|
"""
|
||||||
|> Repo.query()
|
|> Repo.query()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
|
||||||
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Bookmark
|
alias Pleroma.Bookmark
|
||||||
|
alias Pleroma.Hashtag
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
@ -550,6 +551,39 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
|
||||||
|
|
||||||
assert length(activities) == 3
|
assert length(activities) == 3
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it prunes hashtags with no objects associated", %{old_insert_date: old_insert_date} do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
{:ok, hashtag_post_activity} =
|
||||||
|
CommonAPI.post(user, %{status: "morning #cofe", local: true})
|
||||||
|
|
||||||
|
hashtag_post_object = Object.normalize(hashtag_post_activity)
|
||||||
|
|
||||||
|
{:ok, hashtag_post2_activity} =
|
||||||
|
CommonAPI.post(user, %{status: "morning #cawfee", local: true})
|
||||||
|
|
||||||
|
hashtag_post2_object = Object.normalize(hashtag_post2_activity)
|
||||||
|
|
||||||
|
hashtag_post_object
|
||||||
|
|> Ecto.Changeset.change(%{updated_at: old_insert_date})
|
||||||
|
|> Repo.update!()
|
||||||
|
|
||||||
|
hashtag_post2_object
|
||||||
|
|> Ecto.Changeset.change(%{updated_at: old_insert_date})
|
||||||
|
|> Repo.update!()
|
||||||
|
|
||||||
|
# Test whether hashtags with follow relationships are kept
|
||||||
|
User.follow_hashtag(user, Hashtag.get_by_name("cofe"))
|
||||||
|
|
||||||
|
assert length(Repo.all(Hashtag)) == 2
|
||||||
|
assert length(Repo.all(Object)) == 2
|
||||||
|
|
||||||
|
Mix.Tasks.Pleroma.Database.run(["prune_objects"])
|
||||||
|
assert length(Repo.all(Hashtag)) == 1
|
||||||
|
assert length(Repo.all(Object)) == 0
|
||||||
|
assert Repo.one(Hashtag) |> Map.fetch!(:name) == "cofe"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "running update_users_following_followers_counts" do
|
describe "running update_users_following_followers_counts" do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue