[Posts] Remove dead query code

This commit is contained in:
Earlopain 2021-08-14 13:51:50 +02:00
parent 1c0c3c2475
commit b92ceb9b0a
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
2 changed files with 1 additions and 103 deletions

View File

@ -230,76 +230,6 @@ class PostQueryBuilder
end
end
if q[:disapproval]
q[:disapproval].each do |disapproval|
disapprovals = CurrentUser.user.post_disapprovals.select(:post_id)
if disapproval.in?(%w[none false])
relation = relation.where.not("posts.id": disapprovals)
elsif disapproval.in?(%w[any all true])
relation = relation.where("posts.id": disapprovals)
else
relation = relation.where("posts.id": disapprovals.where(reason: disapproval))
end
end
end
if q[:disapproval_neg]
q[:disapproval_neg].each do |disapproval|
disapprovals = CurrentUser.user.post_disapprovals.select(:post_id)
if disapproval.in?(%w[none false])
relation = relation.where("posts.id": disapprovals)
elsif disapproval.in?(%w[any all true])
relation = relation.where.not("posts.id": disapprovals)
else
relation = relation.where.not("posts.id": disapprovals.where(reason: disapproval))
end
end
end
if q[:flagger_ids_neg]
q[:flagger_ids_neg].each do |flagger_id|
if CurrentUser.can_view_flagger?(flagger_id)
post_ids = PostFlag.unscoped.search({:creator_id => flagger_id, :category => "normal"}).reorder("").pluck(:post_id).uniq
if post_ids.any?
relation = relation.where.not("posts.id": post_ids)
end
end
end
end
if q[:flagger_ids]
q[:flagger_ids].each do |flagger_id|
if flagger_id == "any"
relation = relation.where('EXISTS (' + PostFlag.unscoped.search({:category => "normal"}).where('post_id = posts.id').reorder('').select('1').to_sql + ')')
elsif flagger_id == "none"
relation = relation.where('NOT EXISTS (' + PostFlag.unscoped.search({:category => "normal"}).where('post_id = posts.id').reorder('').select('1').to_sql + ')')
elsif CurrentUser.can_view_flagger?(flagger_id)
post_ids = PostFlag.unscoped.search({:creator_id => flagger_id, :category => "normal"}).reorder("").pluck(:post_id).uniq
relation = relation.where("posts.id": post_ids)
end
end
end
if q[:appealer_ids_neg]
q[:appealer_ids_neg].each do |appealer_id|
relation = relation.where.not("posts.id": PostAppeal.unscoped.where(creator_id: appealer_id).select(:post_id).distinct)
end
end
if q[:appealer_ids]
q[:appealer_ids].each do |appealer_id|
if appealer_id == "any"
relation = relation.where('EXISTS (' + PostAppeal.unscoped.where('post_id = posts.id').select('1').to_sql + ')')
elsif appealer_id == "none"
relation = relation.where('NOT EXISTS (' + PostAppeal.unscoped.where('post_id = posts.id').select('1').to_sql + ')')
else
relation = relation.where("posts.id": PostAppeal.unscoped.where(creator_id: appealer_id).select(:post_id).distinct)
end
end
end
if q[:commenter_ids]
q[:commenter_ids].each do |commenter_id|
if commenter_id == "any"
@ -330,12 +260,6 @@ class PostQueryBuilder
end
end
if q[:artcomm_ids]
q[:artcomm_ids].each do |artcomm_id|
relation = relation.where("posts.id": ArtistCommentaryVersion.unscoped.where(updater_id: artcomm_id).select("post_id").distinct)
end
end
if q[:post_id_negated]
relation = relation.where("posts.id <> ?", q[:post_id_negated])
end
@ -413,26 +337,6 @@ class PostQueryBuilder
relation = relation.joins("JOIN (#{pool_posts.to_sql}) pool_posts ON pool_posts.post_id = posts.id").order("pool_posts.pool_index ASC")
end
if q[:favgroups_neg].present?
q[:favgroups_neg].each do |favgroup_rec|
favgroup_id = favgroup_rec.to_i
favgroup = FavoriteGroup.where("favorite_groups.id = ?", favgroup_id).first
if favgroup
relation = relation.where.not("posts.id": favgroup.post_id_array)
end
end
end
if q[:favgroups].present?
q[:favgroups].each do |favgroup_rec|
favgroup_id = favgroup_rec.to_i
favgroup = FavoriteGroup.where("favorite_groups.id = ?", favgroup_id).first
if favgroup
relation = relation.where("posts.id": favgroup.post_id_array)
end
end
end
if q[:upvote].present?
user_id = q[:upvote]
post_ids = PostVote.where(:user_id => user_id).where("score > 0").limit(400).pluck(:post_id)
@ -445,12 +349,6 @@ class PostQueryBuilder
relation = relation.where("posts.id": post_ids)
end
if q[:ordfav].present?
user_id = q[:ordfav].to_i
relation = relation.joins("INNER JOIN favorites ON favorites.post_id = posts.id")
relation = relation.where("favorites.user_id % 100 = ? and favorites.user_id = ?", user_id % 100, user_id).order("favorites.id DESC")
end
# HACK: if we're using a date: or age: metatag, default to ordering by
# created_at instead of id so that the query will use the created_at index.
if q[:date].present? || q[:age].present?

View File

@ -271,7 +271,7 @@ class PostPresenter < Presenter
end
def has_sequential_navigation?(params)
return false if Tag.has_metatag?(params[:q], :order, :ordfav, :ordpool)
return false if Tag.has_metatag?(params[:q], :order, :ordpool)
return false if params[:pool_id].present? || params[:post_set_id].present?
true
end