limit data page to 1-3000 collections
authorTom Clegg <tom@clinicalfuture.com>
Tue, 5 Feb 2013 00:09:03 +0000 (16:09 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Tue, 5 Feb 2013 00:09:03 +0000 (16:09 -0800)
app/controllers/collections_controller.rb
app/models/orvos_base.rb
app/models/orvos_resource_list.rb

index 09d4fe5c884ef5bb3c1796dce8fadcb342a3e088..a61875cdad1d69458bc2079e3bc54ed5c6ddc380 100644 (file)
@@ -6,9 +6,12 @@ class CollectionsController < ApplicationController
   end
 
   def index
-    @links = Link.eager.where(head_kind: 'orvos#collection') |
-      Link.eager.where(tail_kind: 'orvos#collection')
+    @links = Link.eager.limit(1000).where(head_kind: 'orvos#collection') |
+      Link.eager.limit(1000).where(tail_kind: 'orvos#collection')
     @collections = {}
+    Collection.limit(1000).where({}).each do |c|
+      @collections[c.uuid] = {uuid: c.uuid}
+    end
     @links.each do |l|
       if l.head_kind == 'orvos#collection'
         c = (@collections[l.head_uuid] ||= {uuid: l.head_uuid})
index 838133ae9cf5bf744b2899be0b0be2b3e90f7da7..96016059cad97d232c5a177698cafaf117cc5cc5 100644 (file)
@@ -31,6 +31,9 @@ class OrvosBase < ActiveRecord::Base
   def self.where(*args)
     OrvosResourceList.new(self).where(*args)
   end
+  def self.limit(*args)
+    OrvosResourceList.new(self).limit(*args)
+  end
   def self.eager(*args)
     OrvosResourceList.new(self).eager(*args)
   end
index 181a21cf88589a3708d39897f9fd042683c0b994..e1ec35df9cd433bd85c5172cc255dcd0797ad023 100644 (file)
@@ -8,6 +8,11 @@ class OrvosResourceList
     self
   end
 
+  def limit(max_results)
+    @limit = max_results
+    self
+  end
+
   def where(cond)
     cond = cond.dup
     cond.keys.each do |uuid_key|
@@ -33,11 +38,13 @@ class OrvosResourceList
         cond = cond.merge({ kind_key => 'orvos#' + $orvos_api_client.class_kind(cond[kind_key]) })
       end
     end
-    res = $orvos_api_client.api @resource_class, '', {
+    api_params = {
       _method: 'GET',
-      where: cond,
-      eager: (@eager ? '1' : '0')
+      where: cond
     }
+    api_params[:eager] = '1' if @eager
+    api_params[:limit] = @limit if @limit
+    res = $orvos_api_client.api @resource_class, '', api_params
     @results = $orvos_api_client.unpack_api_response res
   end