Use bulk i18n lookups to improve performance #844

Closed
the8472 opened this Issue Apr 25, 2012 · 2 comments

Projects

None yet

2 participants

@the8472
the8472 commented Apr 25, 2012

In a form it's quite likely that there will be multiple labels for different fields of the same object. So it would make sense to use the i18n gem's ability to perform bulk lookups.

Here a lookup for a single attribute of the User class, which causes a lookup to the memcache store i'm using:

1.8.7 :006 > I18n.t "activerecord.attributes.user.firstname"
2012-04-25T13:21:50+02:00 [DEBUG] 27943 : Cache read: i18n//en/2330158/2269918
2012-04-25T13:21:50+02:00 [DEBUG] 27943 : Cache write: i18n//en/2330158/2269918
 => "Firstname" 

If the user form has 10 fields that means 10 queries to the underlying storage, which may be reasonably fast if it's an in-process memory cache but incurs unnecessary latency if it's a memcache on the different host (even if it's on the same server rack).

Instead the following can be used and cached in the form-builder:

1.8.7 :005 > I18n.t "activerecord.attributes.user"
2012-04-25T13:21:31+02:00 [DEBUG] 27943 : Cache read: i18n//en/2330078/2269918
2012-04-25T13:21:31+02:00 [DEBUG] 27943 : Cache write: i18n//en/2330078/2269918
 => {:salutation=>"Salutation", :updated_at=>"Updated at", :birth_name=>"Birth name", :fullname=>"Name", :name_affix=>"Name affix",  :title=>"Title", :timezone=>"Timezone", :name_prefix=>"Name prefix", :lastname=>"Lastname", :direct_permissions=>"direct permissions", :telephone=>"Telephone", :password=>"Password", :firstname=>"Firstname", :email=>"EMail", :created_at=>"Created at", :fax=>"Fax", :groups=>"Groups"} 

That way only one lookup per scope and class is needed when a form is built. This behavior probably should be optional as not all i18n stores might support bulk lookups.

@justinfrench
Owner

Would love to see a pull request for this!

@justinfrench
Owner

Closing since there's been not action in 6 months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment