From c936a9624c98237c04d5c339cad44e65ab447b10 Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 6 Mar 2020 15:10:19 -0600 Subject: [PATCH] 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. --- app/models/artist.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/artist.rb b/app/models/artist.rb index c51854912..4fdb8d9d1 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -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