X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/79548cf316986bb06dde783dbdfea9c5584ac886..b31cc1c673b03aec2a77b81a6bfc1da676a9dc69:/apps/workbench/app/models/arvados_base.rb diff --git a/apps/workbench/app/models/arvados_base.rb b/apps/workbench/app/models/arvados_base.rb index 5c7e44f136..72b76a5229 100644 --- a/apps/workbench/app/models/arvados_base.rb +++ b/apps/workbench/app/models/arvados_base.rb @@ -68,11 +68,21 @@ class ArvadosBase < ActiveRecord::Base self.columns @attribute_info end - def self.find(uuid) + def self.find(uuid, opts={}) if uuid.class != String or uuid.length < 27 then raise 'argument to find() must be a uuid string. Acceptable formats: warehouse locator or string with format xxxxx-xxxxx-xxxxxxxxxxxxxxx' end - new.private_reload(uuid) + + # Only do one lookup on the API side per {class, uuid, workbench + # request} unless {cache: false} is given via opts. + cache_key = "request_#{Thread.current.object_id}_#{self.to_s}_#{uuid}" + if opts[:cache] == false + Rails.cache.write cache_key, $arvados_api_client.api(self, '/' + uuid) + end + hash = Rails.cache.fetch cache_key do + $arvados_api_client.api(self, '/' + uuid) + end + new.private_reload(hash) end def self.order(*args) ArvadosResourceList.new(self).order(*args) @@ -262,9 +272,7 @@ class ArvadosBase < ActiveRecord::Base end def friendly_link_name - if self.class.column_names.include? 'name' - self.name - end + (name if self.respond_to? :name) || uuid end protected