Ruby on Rails Monday, April 30, 2012

If your strategy is to just keep the newest MAXNUMBER records you might consider just adding an after_create method to your model.

On Friday, April 27, 2012 4:56:30 PM UTC-4, Colin Law wrote:

On 27 April 2012 16:23, Jedrin <jrubiando@gmail.com> wrote:
>  We want to use SQL/active record for logging but limit the table size
> so that older messages disappear off of the table Some process has to
> run periodically to do that.
>
> Suppose I want to keep my table size to not much bigger than
> 50,000,000 rows or so. What is the easiest, most efficient way to
> delete any extra rows that there may be ? This is an SQL/active record
> problem I have not encountered before.
>
>  I would know in theory how to get all the records as an array by
> calling MyLog.find(:all) and ordering it by date and then iterating
> from where I want to chop off to the end and deleting each one, but
> that may not be the most efficient or acceptable way to do that.

If you have a reasonably consistent number of new records each day or
week or whatever then you could delete old ones by date rather than
count, so keeping six months worth of records for example.  This would
be much easier as you could just find the records where created_at is
before a given date and delete them.  Put an index on created_at
obviously.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/xzIqMB-OhlYJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
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.

No comments:

Post a Comment