mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27: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
|
||||
alias Philomena.Batch
|
||||
alias Philomena.Elasticsearch
|
||||
alias Philomena.Users.User
|
||||
alias Philomena.Images.Image
|
||||
alias Philomena.Images
|
||||
alias Philomena.ImageVotes.ImageVote
|
||||
|
@ -13,7 +14,13 @@ defmodule Philomena.UserDownvoteWipe do
|
|||
|> where(user_id: ^user.id, up: false)
|
||||
|> Batch.query_batches([id_field: :image_id], fn queryable ->
|
||||
{_, 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)
|
||||
end)
|
||||
|
@ -24,7 +31,12 @@ defmodule Philomena.UserDownvoteWipe do
|
|||
|> Batch.query_batches([id_field: :image_id], fn queryable ->
|
||||
{_, 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)
|
||||
end)
|
||||
|
@ -33,7 +45,11 @@ defmodule Philomena.UserDownvoteWipe do
|
|||
|> where(user_id: ^user.id)
|
||||
|> Batch.query_batches([id_field: :image_id], fn queryable ->
|
||||
{_, image_ids} = Repo.delete_all(select(queryable, [i_f], i_f.image_id))
|
||||
Repo.update_all(where(Image, [i], i.id in ^image_ids), inc: [faves_count: -1])
|
||||
|
||||
{count, nil} =
|
||||
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)
|
||||
end)
|
||||
|
|
Loading…
Reference in a new issue