6074: Use each instead of find_each, so our order() and limit() constraints are respe...
[arvados.git] / services / api / app / controllers / application_controller.rb
index 3a3f6d334589058b3e3af1c0dc13c97cfbf4bff3..e91e3ce03ec6369addee5d63964ac10e198e251a 100644 (file)
@@ -306,11 +306,15 @@ class ApplicationController < ActionController::Base
                limit_columns.map { |s| "octet_length(#{s})" }.join(" + "))
       new_limit = 0
       read_total = 0
-      limit_query.find_each do |record|
+      limit_query.each do |record|
         new_limit += 1
         read_total += record.read_length.to_i
-        break if ((read_total >= Rails.configuration.max_index_database_read) or
-                  (new_limit >= @limit))
+        if read_total >= Rails.configuration.max_index_database_read
+          new_limit -= 1 if new_limit > 1
+          break
+        elsif new_limit >= @limit
+          break
+        end
       end
       @limit = new_limit
       @objects = @objects.limit(@limit)