1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Removed ids_in_list_limit in favor of in_clause_length defined in database_limits.rb

This commit is contained in:
Alex Rothenberg 2010-11-23 06:10:19 +08:00 committed by Aaron Patterson
parent 21fd93cedd
commit 66c09372f3
3 changed files with 9 additions and 14 deletions

View file

@ -391,9 +391,9 @@ module ActiveRecord
# Some databases impose a limit on the number of ids in a list (in Oracle its 1000)
# Make several smaller queries if necessary or make one query if the adapter supports it
def associated_records(ids)
max_ids_in_a_list = connection.ids_in_list_limit || ids.size
in_clause_length = connection.in_clause_length || ids.size
records = []
ids.each_slice(max_ids_in_a_list) do |some_ids|
ids.each_slice(in_clause_length) do |some_ids|
records += yield(some_ids)
end
records

View file

@ -91,11 +91,6 @@ module ActiveRecord
false
end
# Does this adapter restrict the number of ids you can use in a list. Oracle has a limit of 1000.
def ids_in_list_limit
nil
end
# QUOTING ==================================================
# Override to return the quoted table name. Defaults to column quoting.

View file

@ -80,31 +80,31 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_preloading_has_many_in_multiple_queries_with_more_ids_than_database_can_handle
Post.connection.expects(:ids_in_list_limit).at_least_once.returns(5)
Post.connection.expects(:in_clause_length).at_least_once.returns(5)
posts = Post.find(:all, :include=>:comments)
assert_equal 7, posts.size
end
def test_preloading_has_many_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle
Post.connection.expects(:ids_in_list_limit).at_least_once.returns(nil)
Post.connection.expects(:in_clause_length).at_least_once.returns(nil)
posts = Post.find(:all, :include=>:comments)
assert_equal 7, posts.size
end
def test_preloading_habtm_in_multiple_queries_with_more_ids_than_database_can_handle
Post.connection.expects(:ids_in_list_limit).at_least_once.returns(5)
Post.connection.expects(:in_clause_length).at_least_once.returns(5)
posts = Post.find(:all, :include=>:categories)
assert_equal 7, posts.size
end
def test_preloading_habtm_in_one_queries_when_database_has_no_limit_on_ids_it_can_handle
Post.connection.expects(:ids_in_list_limit).at_least_once.returns(nil)
Post.connection.expects(:in_clause_length).at_least_once.returns(nil)
posts = Post.find(:all, :include=>:categories)
assert_equal 7, posts.size
end
def test_load_associated_records_in_one_query_when_adapter_has_no_limit
Post.connection.expects(:ids_in_list_limit).at_least_once.returns(nil)
Post.connection.expects(:in_clause_length).at_least_once.returns(nil)
Post.expects(:i_was_called).with([1,2,3,4,5,6,7]).returns([1])
associated_records = Post.send(:associated_records, [1,2,3,4,5,6,7]) do |some_ids|
Post.i_was_called(some_ids)
@ -113,7 +113,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_load_associated_records_in_several_queries_when_many_ids_passed
Post.connection.expects(:ids_in_list_limit).at_least_once.returns(5)
Post.connection.expects(:in_clause_length).at_least_once.returns(5)
Post.expects(:i_was_called).with([1,2,3,4,5]).returns([1])
Post.expects(:i_was_called).with([6,7]).returns([6])
associated_records = Post.send(:associated_records, [1,2,3,4,5,6,7]) do |some_ids|
@ -123,7 +123,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
end
def test_load_associated_records_in_one_query_when_a_few_ids_passed
Post.connection.expects(:ids_in_list_limit).at_least_once.returns(5)
Post.connection.expects(:in_clause_length).at_least_once.returns(5)
Post.expects(:i_was_called).with([1,2,3]).returns([1])
associated_records = Post.send(:associated_records, [1,2,3]) do |some_ids|
Post.i_was_called(some_ids)