Home Rails Pluck Vs Map
Post
Cancel

Rails Pluck Vs Map

refer to:  https://stackoverflow.com/questions/45347317/which-one-is-faster-between-map-collect-select-and-pluck

pluck:  pick 1 attribute from array

map: re-implement your function

my_array.map(&:id)

my_array.pluck(:id) 

the same.  pluck faster than map

XXTransaction Pluck (0.3ms)  SELECT "xx_transactions"."id" FROM "xx_transactions" WHERE "xx_transactions"."id" = $1  [["id", 18068574]]
XXTransaction Load (0.5ms)  SELECT "xx_transactions".* FROM "xx_transactions" WHERE "xx_transactions"."id" = $1  [["id", 18068574]]
This post is licensed under CC BY 4.0 by the author.