Limit user in a perl script

I try to search for users with no connections to any ticket and no
connection to any attachments to delete them later.

I can’t use rt-shredder directly :wink:

I try this:

my $user = RT::User->new($RT::SystemUser);
my $users = RT::Users->new($RT::SystemUser);
my $tix = RT::Tickets->new($RT::SystemUser);

$users->FindAllRows ;

while (my $uid = $users->next ) {
my $tickets = RT::Tickets->new($RT::SystemUser);
Type = “ticket” AND
Watcher ="’.$user->EmailAddress.’"’);

Delete_User if ! $tickets->Count();

But takes much time (about 10s per user ) in my system for every user.

~500.000 tickets
~ 61.100 users

Is there a better method to limit the user with no tickets and no