[ARVADOS] updated: 198b34d92461b8b4e0ae92eed75b5a3b3577e6ca

git at public.curoverse.com git at public.curoverse.com
Mon Aug 11 14:59:25 EDT 2014


Summary of changes:
 .../api/app/controllers/application_controller.rb  | 16 +++++++++++-----
 .../arvados/v1/collections_controller.rb           |  6 ------
 services/api/app/models/arvados_model.rb           | 22 ++++++++++++++++++++++
 services/api/app/models/collection.rb              |  6 ++++++
 4 files changed, 39 insertions(+), 11 deletions(-)

       via  198b34d92461b8b4e0ae92eed75b5a3b3577e6ca (commit)
      from  73c1fd44fed413866e5fdf97b5f8899c6d3c4a85 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 198b34d92461b8b4e0ae92eed75b5a3b3577e6ca
Author: Brett Smith <brett at curoverse.com>
Date:   Mon Aug 11 15:00:53 2014 -0400

    3412: Generalize API support for selecting non-database columns.
    
    Per feedback in #3412.  This makes the support more general so it's
    easier for other models to use.

diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb
index ba4b544..d3b5c6b 100644
--- a/services/api/app/controllers/application_controller.rb
+++ b/services/api/app/controllers/application_controller.rb
@@ -203,11 +203,17 @@ class ApplicationController < ActionController::Base
       end
     end
 
-    # Find the real column names in @select, resolve those to fully-qualified
-    # SQL column names, and pass the resulting string to the select method.
-    @objects = @objects.select((@select & model_class.columns.map { |c| c.name.to_s })
-                                 .map { |s| "#{table_name}.#{ActiveRecord::Base.connection.quote_column_name s.to_s}" }
-                                 .join ", ") if @select
+    if @select
+      # Map attribute names in @select to real column names, resolve
+      # those to fully-qualified SQL column names, and pass the
+      # resulting string to the select method.
+      api_column_map = model_class.attributes_required_columns
+      columns_list = @select.
+        flat_map { |attr| api_column_map[attr] }.
+        uniq.
+        map { |s| "#{table_name}.#{ActiveRecord::Base.connection.quote_column_name s}" }
+      @objects = @objects.select(columns_list.join(", "))
+    end
     @objects = @objects.order(@orders.join ", ") if @orders.any?
     @objects = @objects.limit(@limit)
     @objects = @objects.offset(@offset)
diff --git a/services/api/app/controllers/arvados/v1/collections_controller.rb b/services/api/app/controllers/arvados/v1/collections_controller.rb
index ca8da31..65387ac 100644
--- a/services/api/app/controllers/arvados/v1/collections_controller.rb
+++ b/services/api/app/controllers/arvados/v1/collections_controller.rb
@@ -260,13 +260,7 @@ class Arvados::V1::CollectionsController < ApplicationController
     # need to fetch it during search, then hide it from the results.
     @select ||= model_class.api_accessible_attributes(:user).
       map { |attr_spec| attr_spec.first.to_s } - ["manifest_text"]
-    render_select = @select.dup
-    if (@select & ["data_size", "files"]).any? and
-        (not @select.include?("manifest_text"))
-      @select << "manifest_text"
-    end
     super
-    @select = render_select
   end
 
   def find_object_by_uuid
diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb
index 1247e36..f736466 100644
--- a/services/api/app/models/arvados_model.rb
+++ b/services/api/app/models/arvados_model.rb
@@ -68,6 +68,28 @@ class ArvadosModel < ActiveRecord::Base
     self.columns.select { |col| col.name == attr.to_s }.first
   end
 
+  def self.attributes_required_columns
+    # This method returns a hash.  Each key is the name of an API attribute,
+    # and it's mapped to a list of database columns that must be fetched
+    # to generate that attribute.
+    # This implementation generates a simple map of attributes to
+    # matching column names.  Child classes can override this method
+    # to specify that method-backed API attributes need to fetch
+    # specific columns from the database.
+    all_columns = columns.map(&:name)
+    api_column_map = Hash.new { |hash, key| hash[key] = [] }
+    methods.grep(/^api_accessible_\w+$/).each do |method_name|
+      next if method_name == :api_accessible_attributes
+      send(method_name).each_pair do |api_attr_name, col_name|
+        col_name = col_name.to_s
+        if all_columns.include?(col_name)
+          api_column_map[api_attr_name.to_s] |= [col_name]
+        end
+      end
+    end
+    api_column_map
+  end
+
   # Return nil if current user is not allowed to see the list of
   # writers. Otherwise, return a list of user_ and group_uuids with
   # write permission. (If not returning nil, current_user is always in
diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb
index e153f3b..ac845f5 100644
--- a/services/api/app/models/collection.rb
+++ b/services/api/app/models/collection.rb
@@ -9,6 +9,12 @@ class Collection < ArvadosModel
     t.add :manifest_text
   end
 
+  def self.attributes_required_columns
+    super.merge({ "data_size" => ["manifest_text"],
+                  "files" => ["manifest_text"],
+                })
+  end
+
   def redundancy_status
     if redundancy_confirmed_as.nil?
       'unconfirmed'

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list