Template.select([:name]).group(:name).having("count(name) > 1").reorder(nil).all.size
D, [2019-08-26T13:40:29.299683 #99] DEBUG -- : Template Load (1.5ms) SELECT "templates"."name" FROM "templates" GROUP BY "templates"."name" HAVING (count(name) > 1) LIMIT $1 [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<Template id: nil, name: "Store Page (2510)">, #<Template id: nil, name: "business-jsonld">, #<Template id: nil, name: "Change me">, #<Template id: nil, name: "Hero Store Page (2510)">]>
irb(main):012:0> Template.select([:name]).group(:name).having("count(name) > 1").reorder(nil).all.count
D, [2019-08-26T13:40:34.657327 #99] DEBUG -- : (1.6ms) SELECT COUNT("templates"."name") AS count_name, "templates"."name", "templates"."name" AS templates_name FROM "templates" GROUP BY "templates"."name" HAVING (count(name) > 1)
=> {"Store Page (2510)"=>2, "business-jsonld"=>2, "Change me"=>2, "Hero Store Page (2510)"=>2}