#!/usr/bin/perl
use lib "/opt/rt3/lib";
use strict;

use Benchmark qw(timeit timestr);
use RT;
RT::LoadConfig;
RT::Init;

use RT::CurrentUser;
my $cuser = RT::CurrentUser->new( );
$cuser->LoadByName('cubic');

use RT::Tickets;

sub walk
{
	my $s = 0;
	my $cuser = shift;
	my $ts = RT::Tickets->new( $cuser );
	$ts->LimitOwner( VALUE => $cuser->id );

	while( my $t = $ts->Next ) {
		my $trxs = $t->Transactions;
		while( my $trx = $trxs->Next ) {
			my $as = $trx->Attachments;
			while( my $a = $as->Next ) {
				my $s += $a->ContentLength || 0;
			}
		}
	}
	return $s;
}

walk($cuser);

print timestr( timeit (5, sub { walk($cuser) } ) ) ."\n";
