From 50d7e448e8823ed53f7a4e8fcd12bc3cf3353cf6 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Fri, 26 Dec 2014 17:40:30 -0700 Subject: Inform Arel that we don't need additional type casting in batching Part of the larger refactoring to remove type casting from Arel. We can inform it that we already have the right type by wrapping the value in an `Arel::Nodes::Quoted`. This commit can be reverted when we have removed type casting from Arel in Rail 5.1 --- activerecord/lib/active_record/relation/batches.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/relation/batches.rb b/activerecord/lib/active_record/relation/batches.rb index ac13b37dce..9f20db831b 100644 --- a/activerecord/lib/active_record/relation/batches.rb +++ b/activerecord/lib/active_record/relation/batches.rb @@ -102,9 +102,15 @@ module ActiveRecord start = options[:start] batch_size = options[:batch_size] || 1000 + if start + # FIXME: Remove this when type casting is removed from Arel + # (Rails 5.1). We can pass start directly instead. + quoted_start = Arel::Nodes::Quoted.new(start) + end + unless block_given? return to_enum(:find_in_batches, options) do - total = start ? where(table[primary_key].gteq(start)).size : size + total = start ? where(table[primary_key].gteq(quoted_start)).size : size (total - 1).div(batch_size) + 1 end end @@ -114,7 +120,7 @@ module ActiveRecord end relation = relation.reorder(batch_order).limit(batch_size) - records = start ? relation.where(table[primary_key].gteq(start)).to_a : relation.to_a + records = start ? relation.where(table[primary_key].gteq(quoted_start)).to_a : relation.to_a while records.any? records_size = records.size -- cgit v1.2.3