3720: Limit Workbench file rendering for large Collections.
authorBrett Smith <brett@curoverse.com>
Wed, 3 Sep 2014 21:52:00 +0000 (17:52 -0400)
committerBrett Smith <brett@curoverse.com>
Fri, 5 Sep 2014 15:16:25 +0000 (11:16 -0400)
Rendering too many files can cause rendering to take too long, and
there's not much point because it can really strain browsers too.
Arbitrarily cap rendering at 10,000 files.

apps/workbench/app/views/collections/_show_files.html.erb
apps/workbench/app/views/collections/show_file_links.html.erb

index d888b2e859b564c2cedba38ad60e0801d567e718..e592ee49599d641d956f487fa73240f9f27e9ab0 100644 (file)
@@ -4,7 +4,7 @@
 <% else %>
   <ul id="collection_files" class="collection_files">
   <% dirstack = [file_tree.first.first] %>
-  <% file_tree.each_with_index do |(dirname, filename, size), index| %>
+  <% file_tree.take(10000).each_with_index do |(dirname, filename, size), index| %>
     <% file_path = CollectionsHelper::file_path([dirname, filename]) %>
     <% while dirstack.any? and (dirstack.last != dirname) %>
       <% dirstack.pop %></ul></li>
index 042e4ff71f7de8a7fca3f478e36950de6c3d99a0..a829d8f274d211d617c83e4f29cd095fbc369e39 100644 (file)
@@ -44,10 +44,11 @@ the entire collection with wget, try:</p>
 
 <h2>File Listing</h2>
 
-<% if @object.andand.files_tree.andand.any? %>
+<% file_tree = @object.andand.files_tree %>
+<% if file_tree.andand.any? %>
   <ul id="collection_files" class="collection_files">
-  <% dirstack = [@object.files_tree.first.first] %>
-  <% @object.files_tree.each_with_index do |(dirname, filename, size), index| %>
+  <% dirstack = [file_tree.first.first] %>
+  <% file_tree.take(10000).each_with_index do |(dirname, filename, size), index| %>
     <% file_path = CollectionsHelper::file_path([dirname, filename]) %>
     <% while dirstack.any? and (dirstack.last != dirname) %>
       <% dirstack.pop %></ul></li>