In a Rails application, I have two models like this :
class Painting < ActiveRecord::Base
belongs_to :artist
end
class Artist < ActiveRecord::Base
belongs_to :country
def display_name
text = to_s
if birth_year
death = death_year || "----"
text += " (#{birth_year}-#{death})"
end
text += ", #{country.name}"
end
end
class Country < ActiveRecord::Base
active_admin_translates :name
end
I use active admin like this
ActiveAdmin.register Painting do
end
The problem is than the display_name
method need to call countries and translations tables. There is a lot of artists and it's very long to run. I'm looking for a way to to increase the speed.
Request seems like this :
SELECT "artists".* FROM "artists" WHERE "artists"."accepted" = 't' ORDER BY name
SELECT "countries".* FROM "countries" WHERE "countries"."id" = 50 ORDER BY name LIMIT 1
All artists are requested to do this input :
What can I do?