From 22c8b6367a9cd79b17240b7dca1ac8f7d8e7ee77 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Wed, 3 Jun 2015 16:37:39 -0400 Subject: [PATCH] 6074: Never exceed the configured max_index_database_read (even by one record) unless necessary to return one row. Fix copy&paste error in test case. --- .../app/controllers/application_controller.rb | 8 ++++++-- .../arvados/v1/collections_controller_test.rb | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb index 3a3f6d3345..1c8450bfdc 100644 --- a/services/api/app/controllers/application_controller.rb +++ b/services/api/app/controllers/application_controller.rb @@ -309,8 +309,12 @@ class ApplicationController < ActionController::Base limit_query.find_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) diff --git a/services/api/test/functional/arvados/v1/collections_controller_test.rb b/services/api/test/functional/arvados/v1/collections_controller_test.rb index 3257e494c5..28de3f8c02 100644 --- a/services/api/test/functional/arvados/v1/collections_controller_test.rb +++ b/services/api/test/functional/arvados/v1/collections_controller_test.rb @@ -103,11 +103,19 @@ class Arvados::V1::CollectionsControllerTest < ActionController::TestCase }.merge(params) end + test "index with manifest_text limited by max_index_database_read returns non-empty" do + request_capped_index() { |_| 1 } + assert_response :success + assert_equal(1, json_response["items"].size) + assert_equal(1, json_response["limit"]) + assert_equal(201, json_response["items_available"]) + end + test "index with manifest_text limited by max_index_database_read" do request_capped_index() { |size| (size * 3) + 1 } assert_response :success - assert_equal(4, json_response["items"].size) - assert_equal(4, json_response["limit"]) + assert_equal(3, json_response["items"].size) + assert_equal(3, json_response["limit"]) assert_equal(201, json_response["items_available"]) end @@ -122,11 +130,11 @@ class Arvados::V1::CollectionsControllerTest < ActionController::TestCase test "max_index_database_read does not interfere with order" do request_capped_index(order: "name DESC") { |size| (size * 15) + 1 } assert_response :success - assert_equal(16, json_response["items"].size) + assert_equal(15, json_response["items"].size) assert_empty(json_response["items"].reject do |coll| coll["name"] !~ /^Collection_9/ end) - assert_equal(16, json_response["limit"]) + assert_equal(15, json_response["limit"]) assert_equal(201, json_response["items_available"]) end -- 2.30.2