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

Dan Horne dan.horne at redbone.co.nz
Tue Jan 26 22:11:38 GMT 2010


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
>





More information about the DBIx-Class mailing list