[LON-CAPA-cvs] cvs: loncom /interface lonmsg.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 05 Jan 2006 20:10:57 -0000


albertel		Thu Jan  5 15:10:57 2006 EDT

  Modified files:              
    /loncom/interface	lonmsg.pm 
  Log:
  - perf improvement, get all of the statuses we'll need in one ::get() rather than iterated gets
  
  
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.168 loncom/interface/lonmsg.pm:1.169
--- loncom/interface/lonmsg.pm:1.168	Thu Jan  5 14:52:52 2006
+++ loncom/interface/lonmsg.pm	Thu Jan  5 15:10:54 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging
 #
-# $Id: lonmsg.pm,v 1.168 2006/01/05 19:52:52 albertel Exp $
+# $Id: lonmsg.pm,v 1.169 2006/01/05 20:10:54 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -267,16 +267,20 @@
 }
 
 sub unpackmsgid {
-    my ($msgid,$folder,$skipstatus)=@_;
+    my ($msgid,$folder,$skipstatus,$status_cache)=@_;
     $msgid=&Apache::lonnet::unescape($msgid);
     my ($sendtime,$shortsubj,$fromname,$fromdomain,$count,$fromcid,
                      $processid)=split(/\:/,&Apache::lonnet::unescape($msgid));
     if (!defined($processid)) { $fromcid = ''; }
     my %status=();
     unless ($skipstatus) {
-        my $suffix=&foldersuffix($folder);
-        %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
-        if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
+	if (ref($status_cache)) {
+	    $status{$msgid} = $status_cache->{$msgid};
+	} else {
+	    my $suffix=&foldersuffix($folder);
+	    %status=&Apache::lonnet::get('email_status'.$suffix,[$msgid]);
+	}
+	if ($status{$msgid}=~/^error\:/) { $status{$msgid}=''; }
         unless ($status{$msgid}) { $status{$msgid}='new'; }
     }
     return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid},$fromcid);
@@ -859,10 +863,13 @@
     #unpack the varibles and repack into temp for sorting
     my @temp;
     my %descriptions;
+    my %status_cache = 
+	&Apache::lonnet::get('email_status'.&foldersuffix($folder),\@messages);
     foreach (@messages) {
 	my $msgid=&Apache::lonnet::escape($_);
 	my ($sendtime,$shortsubj,$fromname,$fromdomain,$status,$fromcid)=
-	    &Apache::lonmsg::unpackmsgid($msgid,$folder);
+	    &Apache::lonmsg::unpackmsgid($msgid,$folder,undef,
+					 \%status_cache);
         my $description = &get_course_desc($fromcid,\%descriptions);
 	my @temp1 = ($sendtime,$shortsubj,$fromname,$fromdomain,$status,
 		     $msgid,$description);
@@ -951,10 +958,7 @@
 				       'op' => 'Open',
 				       'do' => 'Domain'
 				       );
-    my @msgids = sort split(/\&/,&Apache::lonnet::reply
-                            ('keys:'.$env{'user.domain'}.':'.
-                             $env{'user.name'}.':nohist_email',
-                             $env{'user.home'}));
+    my @msgids = sort(&Apache::lonnet::getkeys('nohist_email'));
     my @newmsgs;
     my %setters = ();
     my $startblock = 0;
@@ -963,10 +967,13 @@
     my $numblocked = 0;
     # Check for blocking of display because of scheduled online exams.
     &blockcheck(\%setters,\$startblock,\$endblock);
+    my %status_cache = 
+	&Apache::lonnet::get('email_status',\@msgids);
     my %descriptions;
     foreach (@msgids) {
+	my $msgid=&Apache::lonnet::escape($_);
         my ($sendtime,$shortsubj,$fromname,$fromdom,$status,$fromcid)=
-	    &Apache::lonmsg::unpackmsgid($_);
+	    &Apache::lonmsg::unpackmsgid($msgid,undef,undef,\%status_cache);
         if (defined($sendtime) && $sendtime!~/error/) {
             my $description = &get_course_desc($fromcid,\%descriptions);
             my $numsendtime = $sendtime;
@@ -977,7 +984,7 @@
                     $numblocked ++;
                 } else {
                     push @newmsgs, { 
-                        msgid    => $_,
+                        msgid    => $msgid,
                         sendtime => $sendtime,
                         shortsub => &Apache::lonnet::unescape($shortsubj),
                         from     => $fromname,