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:
@@ -404,9 +404,9 @@ class Artist < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
if params[:has_tag].to_s.truthy?
|
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?
|
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
|
end
|
||||||
|
|
||||||
case params[:order]
|
case params[:order]
|
||||||
@@ -415,7 +415,7 @@ class Artist < ApplicationRecord
|
|||||||
when "updated_at"
|
when "updated_at"
|
||||||
q = q.order("artists.updated_at desc")
|
q = q.order("artists.updated_at desc")
|
||||||
when "post_count"
|
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
|
else
|
||||||
q = q.apply_default_order(params)
|
q = q.apply_default_order(params)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user