11580: preload containers
authorradhika <radhika@curoverse.com>
Tue, 16 May 2017 19:33:31 +0000 (15:33 -0400)
committerradhika <radhika@curoverse.com>
Wed, 17 May 2017 18:28:15 +0000 (14:28 -0400)
apps/workbench/app/assets/javascripts/filterable.js
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/controllers/container_requests_controller.rb
apps/workbench/app/models/container_work_unit.rb
apps/workbench/app/views/container_requests/_show_recent.html.erb
apps/workbench/test/integration/container_requests_test.rb

index 27473ad28585a7d44504465299bfbb4cc4656916..5f6370c2905171bda848622f9d2e6e638d33ad9b 100644 (file)
@@ -55,7 +55,7 @@ function updateFilterableQueryNow($target) {
     if (newquery == null || newquery == '') {
       params.filters = [];
     } else {
-      params.filters = [['any', '@@', newquery.concat(':*')]];
+      params.filters = [['any', '@@', newquery.trim().concat(':*')]];
     }
     $target.data('infinite-content-params-filterable', params);
     $target.data('filterable-query', newquery);
index a63fe6e21f1311a353392a2bc2f27f656147bee5..0a40f58f21512b479f130fa6de773eac9703700a 100644 (file)
@@ -1234,8 +1234,15 @@ class ApplicationController < ActionController::Base
         @objects_for[obj.name] = obj
       end
     else
+      key_prefix = "request_#{Thread.current.object_id}_#{dataclass.to_s}_"
       dataclass.where(uuid: uuids).each do |obj|
         @objects_for[obj.uuid] = obj
+        if dataclass == Collection
+          # The collecions#index defaults to "all attributes except manifest_text"
+          # Hence, this object is not suitable for preloading the find() cache.
+        else
+          Rails.cache.write(key_prefix + obj.uuid, obj.as_json)
+        end
       end
     end
     @objects_for
index 6eaed2d555975f54396ef15fa4d5b915dc356ad0..a507139225f216cad62247f2776655a51568f871 100644 (file)
@@ -165,4 +165,10 @@ class ContainerRequestsController < ApplicationController
 
     super
   end
+
+  def index
+    @limit = 20
+    super
+  end
+
 end
index 84fc1f8f0978e16a86bd34fde8d07a6d2d9cd7c1..afdc91e4dd1fcb55d574b919da597e6cd93fa07b 100644 (file)
@@ -6,7 +6,7 @@ class ContainerWorkUnit < ProxyWorkUnit
     if @proxied.is_a?(ContainerRequest)
       container_uuid = get(:container_uuid)
       if container_uuid
-        @container = Container.where(uuid: container_uuid).first
+        @container = Container.find(container_uuid)
       end
     end
   end
index 546b076ef3c3fbf51679ffc44795a2401782bb95..6a4c8b18ecc97e30d1c931da18ccdf6020925d14 100644 (file)
@@ -15,7 +15,7 @@
       <th>
         Status
       </th><th>
-        ContainerRequest
+        Container request
       </th><th>
         Description
       </th><th>
index 51b6b247bf7f4e33593adecc93807aa8c21a6f8b..6ac667ed47fa900344570845efb38cbeebe72f9d 100644 (file)
@@ -122,40 +122,31 @@ class ContainerRequestsTest < ActionDispatch::IntegrationTest
     page.assert_selector 'g.node>title', text: cr['uuid'], visible: false
   end
 
-  [
-    'active',
-    'admin',
-  ].each do |token|
-    test "index page as #{token} user" do
-      visit page_with_token(token, "/container_requests")
-
-      running_owner_active = api_fixture("container_requests", "requester_for_running")
-      anon_accessible_cr = api_fixture("container_requests", "running_anonymous_accessible")
-
-      # both of these CRs should be accessible to the user
-      assert_selector "a[href=\"/container_requests/#{running_owner_active['uuid']}\"]", text: running_owner_active[:name]
-      assert_selector "a[href=\"/container_requests/#{anon_accessible_cr['uuid']}\"]", text: anon_accessible_cr[:name]
-
-      # both the active user (owner) and admin can delete the "running" container_request
-      within(".cr-#{running_owner_active['uuid']}") do
-        assert_not_nil first('.glyphicon-trash')
-      end
+  test "index page" do
+    visit page_with_token("active", "/container_requests")
 
-      # only admin user can delete the anonymously accessible container_request
-      within(".cr-#{anon_accessible_cr['uuid']}") do
-        if token == 'admin'
-          assert_not_nil first('.glyphicon-trash')
-        else
-          assert_nil first('.glyphicon-trash')
-        end
-      end
+    running_owner_active = api_fixture("container_requests", "requester_for_running")
+    anon_accessible_cr = api_fixture("container_requests", "running_anonymous_accessible")
 
-      # verify the search box in the page
-      find('.recent-container-requests-filterable-control').set("anonymous")
-      sleep 0.350 # Wait for 250ms debounce timer (see filterable.js)
-      wait_for_ajax
-      assert_no_selector "a[href=\"/container_requests/#{running_owner_active['uuid']}\"]", text: running_owner_active[:name]
-      assert_selector "a[href=\"/container_requests/#{anon_accessible_cr['uuid']}\"]", text: anon_accessible_cr[:name]
+    # both of these CRs should be accessible to the user
+    assert_selector "a[href=\"/container_requests/#{running_owner_active['uuid']}\"]", text: running_owner_active[:name]
+    assert_selector "a[href=\"/container_requests/#{anon_accessible_cr['uuid']}\"]", text: anon_accessible_cr[:name]
+
+    # user can delete the "running" container_request
+    within(".cr-#{running_owner_active['uuid']}") do
+      assert_not_nil first('.glyphicon-trash')
+    end
+
+    # user can not delete the anonymously accessible container_request
+    within(".cr-#{anon_accessible_cr['uuid']}") do
+      assert_nil first('.glyphicon-trash')
     end
+
+    # verify the search box in the page
+    find('.recent-container-requests-filterable-control').set("anonymous")
+    sleep 0.350 # Wait for 250ms debounce timer (see filterable.js)
+    wait_for_ajax
+    assert_no_selector "a[href=\"/container_requests/#{running_owner_active['uuid']}\"]", text: running_owner_active[:name]
+    assert_selector "a[href=\"/container_requests/#{anon_accessible_cr['uuid']}\"]", text: anon_accessible_cr[:name]
   end
 end