I''ve taken this approach:

def self.prune_table
  if self.count > 1000
    youngest_victim = find(:first, :select => :id, :order => 'created_at
desc', :offset => 1000)
    delete_all(["id <= ?",youngest_victim.id])
  end
end

My requirements are not particularly strict around the 1000. Just more or
less around there. You could do the same with created_at I guess.

Any obvious issues with this approach?

Regards
Ivor

On Mon, Aug 17, 2009 at 4:52 PM, Marnen Laibow-Koser <
rails-mailing-l...@andreas-s.net> wrote:

>
> g_f wrote:
> > Doesn't "ORDER BY tstamp" need to be "ORDER BY tstamp DESC"? The
> > latest 10 need to be captured, not the oldest 10.
>
> Yes, and that was a silly mistake on my part.  The query still shows the
> general pattern, though.
>
> Best,
> --
> Marnen Laibow-Koser
> http://www.marnen.org
> mar...@marnen.org
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to