Use LEFT JOIN instead of UNION for hashtag pruning
This commit is contained in:
parent
40da4e88ea
commit
88a8086ad3
1 changed files with 10 additions and 7 deletions
|
@ -343,13 +343,16 @@ def run(["prune_objects" | args]) do
|
||||||
|
|
||||||
%{:num_rows => del_hashtags} =
|
%{:num_rows => del_hashtags} =
|
||||||
"""
|
"""
|
||||||
DELETE FROM hashtags AS ht
|
DELETE FROM hashtags
|
||||||
WHERE NOT EXISTS (
|
USING hashtags AS ht
|
||||||
SELECT 1 FROM hashtags_objects hto
|
LEFT JOIN hashtags_objects hto
|
||||||
WHERE ht.id = hto.hashtag_id
|
ON ht.id = hto.hashtag_id
|
||||||
UNION
|
LEFT JOIN user_follows_hashtag ufht
|
||||||
SELECT 1 FROM user_follows_hashtag ufht
|
ON ht.id = ufht.hashtag_id
|
||||||
WHERE ht.id = ufht.hashtag_id)
|
WHERE
|
||||||
|
hashtags.id = ht.id
|
||||||
|
AND hto.hashtag_id is NULL
|
||||||
|
AND ufht.hashtag_id is NULL
|
||||||
"""
|
"""
|
||||||
|> Repo.query!()
|
|> Repo.query!()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue