I''m testing out ActiveRecord''s find_in_batches and
I''m missing
something very basic I think. I can only get it to return the values
from the first chunk (batch_size) and nothing more...how do I get it
to process chunks until there are no more?
From my Rails 2.3 console, shouldn''t this find_in_batches method print
the same number as the standard count method? I mean, shouldn''t these
be equivalent?
Entry.count(:select => "distinct(email)", :conditions => {
:opt_in =>
true, :blacklist => false })
313954
count = 0
Entry.find_in_batches(:batch_size => 2000, :select =>
"distinct(email)", :conditions => { :opt_in => true, :blacklist
=>
false} ) do |entries|
entries.each { count += 1 }
puts count
end
2000
http://pastie.org/1214575
Thanks for any help!
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Looks like you''re missing the "id" in your :select, which #find_in_batches relies upon. Try: :select => "distinct(email), id" On Oct 12, 12:26 pm, Lee Smith <autige...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m testing out ActiveRecord''s find_in_batches and I''m missing > something very basic I think. I can only get it to return the values > from the first chunk (batch_size) and nothing more...how do I get it > to process chunks until there are no more? > > From my Rails 2.3 console, shouldn''t this find_in_batches method print > the same number as the standard count method? I mean, shouldn''t these > be equivalent? > > Entry.count(:select => "distinct(email)", :conditions => { :opt_in => > true, :blacklist => false }) > > 313954 > > count = 0 > Entry.find_in_batches(:batch_size => 2000, :select => > "distinct(email)", :conditions => { :opt_in => true, :blacklist => > false} ) do |entries| > entries.each { count += 1 } > puts count > end > > 2000 > > http://pastie.org/1214575 > > Thanks for any help!-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Perfect! Thanks Erol. I knew it was something very basic. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.