Commit 848e6b2d authored by Arturo Herrero's avatar Arturo Herrero

Reduce 1 query count using `map` instead of `pluck`

map

  Service Load (0.7ms)  SELECT "services".* FROM "services" WHERE
    "services"."template" = $1 AND "services"."type" IN ($2, $3, $4, $5,
    $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19,
    $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32,
    $33, $34, $35, $36, $37, $38, $39)
  ↳ app/models/service.rb:270:in `map'
  Rendering admin/services/index.html.haml within layouts/admin
  CACHE Service Load (0.1ms)  SELECT "services".* FROM "services" WHERE
    "services"."template" = $1 AND "services"."type" IN ($2, $3, $4, $5,
    $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19,
    $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32,
    $33, $34, $35, $36, $37, $38, $39)
  ↳ app/views/admin/services/index.html.haml:13:in `sort_by'

pluck

   (0.6ms)  SELECT "services"."type" FROM "services" WHERE
     "services"."template" = $1 AND "services"."type" IN ($2, $3, $4,
     $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18,
     $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31,
     $32, $33, $34, $35, $36, $37, $38, $39)
  ↳ app/models/service.rb:270:in `create_nonexistent_templates'
  Rendering admin/services/index.html.haml within layouts/admin
  Service Load (0.5ms)  SELECT "services".* FROM "services" WHERE
    "services"."template" = $1 AND "services"."type" IN ($2, $3, $4, $5,
    $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19,
    $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32,
    $33, $34, $35, $36, $37, $38, $39)
  ↳ app/views/admin/services/index.html.haml:13:in `sort_by'
parent 72e172f0
......@@ -268,7 +268,7 @@ class Service < ApplicationRecord
end
private_class_method def self.create_nonexistent_templates
nonexistent_services = available_services_types - templates.pluck(:type)
nonexistent_services = available_services_types - templates.map(&:type)
return if nonexistent_services.empty?
transaction do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment