[Dbix-class] Removing rows older than a given number of minutes ...

Alexander Hartmaier alexander.hartmaier at t-systems.at
Wed Jan 27 08:48:57 GMT 2010


That's my preferred way of doing this and it works great.

--
Best regards, Alex


Am Dienstag, den 26.01.2010, 23:11 +0100 schrieb Dan Horne:
> Could you do something like this? (untested, but I do use something
> similar to deal with dates on an app I'm running on MySQL and Oracle)
>
> my $threshold_seconds = 300;
> my $date = DateTime->now;
> my $threshold_date = $date->add(seconds => -$threshold_seconds);
> # Convert the DateTime object into the preferred vendor string
> representation of the date
> my $db_date =
> $schema_obj->storage->datetime_parser->format_datetime($threshold_date);
>
> $rs->search({
>     state => $state,
>     last_modified =>  {'<', $db_date}
> })->delete_all;
>
>
>
> Kiffin Gish said:
> > On Tue, 2010-01-26 at 19:51 +0100, Bernhard Graf wrote:
> >> Kiffin Gish schrieb:
> >>
> >> > The lazy man's way out is:
> >> >
> >> > use DateTime;
> >> > use DateTime::Duration;
> >> >
> >> > my @users = $rs->search({state=>$state});
> >> > for my $user (@users) {
> >> >     my $duration = DateTime::Duration->new(DateTime->now -
> >> > $user->last_modified);
> >> >     $user->delete if ($duration->seconds > $limit);
> >> > }
> >> >
> >> > Probably more generic rather than hard-coding SQL stuff.
> >>
> >> Try this on a dataset with a million rows, please.
> >>
> >> L8er  ;*)
> >>
> >> Bernhard Graf
> >
> > Very true, but there must be better ways to do this than the reactions
> > so far.
> >
> >
> > _______________________________________________
> > List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> > IRC: irc.perl.org#dbix-class
> > SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> > Searchable Archive:
> > http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
> >
>
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*



More information about the DBIx-Class mailing list