mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-20 06:37:59 +01:00
adjust counters during wipes (derpibooru/philomena#197)
This commit is contained in:
parent
96f1005255
commit
ff5c01ce07
1 changed files with 19 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
defmodule Philomena.UserDownvoteWipe do
|
defmodule Philomena.UserDownvoteWipe do
|
||||||
alias Philomena.Batch
|
alias Philomena.Batch
|
||||||
alias Philomena.Elasticsearch
|
alias Philomena.Elasticsearch
|
||||||
|
alias Philomena.Users.User
|
||||||
alias Philomena.Images.Image
|
alias Philomena.Images.Image
|
||||||
alias Philomena.Images
|
alias Philomena.Images
|
||||||
alias Philomena.ImageVotes.ImageVote
|
alias Philomena.ImageVotes.ImageVote
|
||||||
|
@ -13,7 +14,13 @@ defmodule Philomena.UserDownvoteWipe do
|
||||||
|> where(user_id: ^user.id, up: false)
|
|> where(user_id: ^user.id, up: false)
|
||||||
|> Batch.query_batches([id_field: :image_id], fn queryable ->
|
|> Batch.query_batches([id_field: :image_id], fn queryable ->
|
||||||
{_, image_ids} = Repo.delete_all(select(queryable, [i_v], i_v.image_id))
|
{_, image_ids} = Repo.delete_all(select(queryable, [i_v], i_v.image_id))
|
||||||
Repo.update_all(where(Image, [i], i.id in ^image_ids), inc: [downvotes_count: -1, score: 1])
|
|
||||||
|
{count, nil} =
|
||||||
|
Repo.update_all(where(Image, [i], i.id in ^image_ids),
|
||||||
|
inc: [downvotes_count: -1, score: 1]
|
||||||
|
)
|
||||||
|
|
||||||
|
Repo.update_all(where(User, id: ^user.id), inc: [votes_cast_count: -count])
|
||||||
|
|
||||||
reindex(image_ids)
|
reindex(image_ids)
|
||||||
end)
|
end)
|
||||||
|
@ -24,7 +31,12 @@ defmodule Philomena.UserDownvoteWipe do
|
||||||
|> Batch.query_batches([id_field: :image_id], fn queryable ->
|
|> Batch.query_batches([id_field: :image_id], fn queryable ->
|
||||||
{_, image_ids} = Repo.delete_all(select(queryable, [i_v], i_v.image_id))
|
{_, image_ids} = Repo.delete_all(select(queryable, [i_v], i_v.image_id))
|
||||||
|
|
||||||
Repo.update_all(where(Image, [i], i.id in ^image_ids), inc: [upvotes_count: -1, score: -1])
|
{count, nil} =
|
||||||
|
Repo.update_all(where(Image, [i], i.id in ^image_ids),
|
||||||
|
inc: [upvotes_count: -1, score: -1]
|
||||||
|
)
|
||||||
|
|
||||||
|
Repo.update_all(where(User, id: ^user.id), inc: [votes_cast_count: -count])
|
||||||
|
|
||||||
reindex(image_ids)
|
reindex(image_ids)
|
||||||
end)
|
end)
|
||||||
|
@ -33,8 +45,12 @@ defmodule Philomena.UserDownvoteWipe do
|
||||||
|> where(user_id: ^user.id)
|
|> where(user_id: ^user.id)
|
||||||
|> Batch.query_batches([id_field: :image_id], fn queryable ->
|
|> Batch.query_batches([id_field: :image_id], fn queryable ->
|
||||||
{_, image_ids} = Repo.delete_all(select(queryable, [i_f], i_f.image_id))
|
{_, image_ids} = Repo.delete_all(select(queryable, [i_f], i_f.image_id))
|
||||||
|
|
||||||
|
{count, nil} =
|
||||||
Repo.update_all(where(Image, [i], i.id in ^image_ids), inc: [faves_count: -1])
|
Repo.update_all(where(Image, [i], i.id in ^image_ids), inc: [faves_count: -1])
|
||||||
|
|
||||||
|
Repo.update_all(where(User, id: ^user.id), inc: [images_favourited_count: -count])
|
||||||
|
|
||||||
reindex(image_ids)
|
reindex(image_ids)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue