artists/index: fix incorrect page counts for has_tag param.

Bug: using the has_tag param caused the paginator to calculate the wrong
page count.

Caused by the join having a DISTINCT clause in the OFFSET/LIMIT query,
but not in the COUNT(*) query.
This commit is contained in:
evazion
2020-03-06 15:10:19 -06:00
parent 4c11e339bd
commit c936a9624c

View File

@@ -404,9 +404,9 @@ class Artist < ApplicationRecord
end
if params[:has_tag].to_s.truthy?
q = q.joins(:tag).where("tags.post_count > 0")
q = q.where(name: Tag.nonempty.select(:name))
elsif params[:has_tag].to_s.falsy?
q = q.includes(:tag).where("tags.name IS NULL OR tags.post_count <= 0").references(:tags)
q = q.where.not(name: Tag.nonempty.select(:name))
end
case params[:order]
@@ -415,7 +415,7 @@ class Artist < ApplicationRecord
when "updated_at"
q = q.order("artists.updated_at desc")
when "post_count"
q = q.includes(:tag).order("tags.post_count desc nulls last").order("artists.name").references(:tags)
q = q.left_outer_joins(:tag).order("tags.post_count desc nulls last").order("artists.name")
else
q = q.apply_default_order(params)
end