[rt-users] R: 2. try ;-) Limit user in a perl script

Scotto Alberto al.scotto at reply.it
Wed Sep 19 11:17:24 EDT 2012


Well, that's normal: you are scanning the whole tickets list again and again, for every user.
You should invert the nested loops such that you scan the tickets only once.

Something like this (kind of pseudo-code):

my $tickets = RT::Tickets->new($RT::SystemUser);
my @users_with_ticket;
# let's collect all the users who relate to some ticket
while (my $t = tickets->next) {
   push @users_with_ticket, $t->Requestor;
   push @users_with_ticket, $t->Owner;
   # push all the other actors
}
# now, let's take the complement of the set users_with_ticket
my $users = RT::Users->new($RT::SystemUser)
my @users_without_ticket;
while(my $u = $users->next) {
   if ($u IS NOT IN $users_with_ticket) push @users_without_ticket, $u;
}

The last loop (just a draft) may still be critical, but considering that, in your case study, the bigger number is given by the tickets, I think you're quite safe.

Regards

AS

________________________________________
Da: rt-users-bounces at lists.bestpractical.com [rt-users-bounces at lists.bestpractical.com] per conto di Björn Schulz [bjoern.schulz at desy.de]
Inviato: mercoledì 19 settembre 2012 15.48
A: rt-users at lists.bestpractical.com
Oggetto: [rt-users]  2. try ;-) Limit user in a perl script

Hi!

I try to ask again, because on my producton system it takes a very long
time to limit users (7 Minutes !!! per user :-(( ).

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 ;-)

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);
 $user->Load($uid);
 $tickets->FromSQL('
    Type = "ticket" AND
    Watcher ="'.$user->EmailAddress.'"');

  Delete_User if ! $tickets->Count();
...



But it takes much time (about 7 minutes 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
attachments or what am I doing wrong?

Cheers,
  Björn

--------
Final RT training for 2012 in Atlanta, GA - October 23 & 24
  http://bestpractical.com/training

We're hiring! http://bestpractical.com/jobs




Alberto Scotto

Blue Reply
Via Cardinal Massaia, 83
10147 - Torino - ITALY
phone: +39 011 29100
al.scotto at reply.it
www.reply.it


________________________________

--
The information transmitted is intended for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.



More information about the rt-users mailing list