I did something similar recently, although my solution might not work
for you, but here it is:
class User < ActiveRecord::Base # There are lots of these
end
class TaskTracker # this consists of nothing more than an id, user_id,
and a completed flag (which is indexed)
belongs_to :user
def perform_task
... do expensive operation on self.user ...
self.completed = true
self.save
end
I create a TaskTracker for every User. (There are various ways to do
this, I did it with a 'select into' directly from sql)
Now, I can do this:
TaskTracker.find(:all, :conditions => 'completed = false', :limit =>
100).each do
|t|
t.perform_task
end
This seems to be pretty quick, perhaps because I don't need to use
offset, and has the advantage that I can stick the processing in a
crontab if I want.
-c
seangeo wrote:
> Thanks for the reply.
>
> I did try paginating using limit and offset, however as I mentioned in
> my original post, the query performance for large values of offset
> degrade quite significantly to the point of increasing your overall
> execution time by an order of magnitude.
>
> So no matter how many rows you fetch per query, using offset doesn't
> scale to large tables.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core
-~----------~----~----~----~------~----~------~--~---