[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 02 Sep 2004 21:23:13 -0000


albertel		Thu Sep  2 17:23:13 2004 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - doing some performance annalysis shows that &symbparm takes a long time (0.1 seconds) when it can't find the symb, which means EXT can take a long time, which means editing a CSTR space problem is slow (speed up for a 8 part problem is from 21 seconds to 0.5 seconds) 
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.538 loncom/lonnet/perl/lonnet.pm:1.539
--- loncom/lonnet/perl/lonnet.pm:1.538	Thu Sep  2 14:01:52 2004
+++ loncom/lonnet/perl/lonnet.pm	Thu Sep  2 17:23:13 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.538 2004/09/02 18:01:52 albertel Exp $
+# $Id: lonnet.pm,v 1.539 2004/09/02 21:23:13 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -50,7 +50,7 @@
 use Apache::loncoursedata;
 use Apache::lonlocal;
 use Storable qw(lock_store lock_nstore lock_retrieve freeze thaw);
-use Time::HiRes();
+use Time::HiRes qw( gettimeofday tv_interval );
 my $readit;
 
 =pod
@@ -4026,11 +4026,14 @@
 
 	my $section;
 	if (defined($courseid) && $courseid eq $ENV{'request.course.id'}) {
+	    if (!$symbparm) { $symbparm=&symbread(); }
+	}
+	if ($symbparm && defined($courseid) && 
+	    $courseid eq $ENV{'request.course.id'}) {
 
 	    #print '<br>'.$space.' - '.$qualifier.' - '.$spacequalifierrest;
 
 # ----------------------------------------------------- Cascading lookup scheme
-	    if (!$symbparm) { $symbparm=&symbread(); }
 	    my $symbp=$symbparm;
 	    my $mapp=(&decode_symb($symbp))[0];
 
@@ -4041,11 +4044,11 @@
 		($ENV{'user.domain'} eq $udom)) {
 		$section=$ENV{'request.course.sec'};
 	    } else {
-                if (! defined($usection)) {
-                    $section=&usection($udom,$uname,$courseid);
-                } else {
-                    $section = $usection;
-                }
+		if (! defined($usection)) {
+		    $section=&usection($udom,$uname,$courseid);
+		} else {
+		    $section = $usection;
+		}
 	    }
 
 	    my $seclevel=$courseid.'.['.$section.'].'.$spacequalifierrest;
@@ -4083,7 +4086,7 @@
 				 $uname." at ".$udom.": ".
 				 $tmp."</font>");
 		    } elsif ($tmp=~/error: 2 /) {
-                        &EXT_cache_set($udom,$uname);
+			&EXT_cache_set($udom,$uname);
 		    } elsif ($tmp =~ /^(con_lost|no_such_host)/) {
 			return $tmp;
 		    }
@@ -4093,10 +4096,10 @@
 # -------------------------------------------------------- second, check course
 
 	    my $coursereply=&courseresdata($ENV{'course.'.$courseid.'.num'},
-					  $ENV{'course.'.$courseid.'.domain'},
-					  ($seclevelr,$seclevelm,$seclevel,
-					   $courselevelr,$courselevelm,
-					   $courselevel));
+					   $ENV{'course.'.$courseid.'.domain'},
+					   ($seclevelr,$seclevelm,$seclevel,
+					    $courselevelr,$courselevelm,
+					    $courselevel));
 	    if (defined($coursereply)) { return $coursereply; }
 
 # ------------------------------------------------------ third, check map parms
@@ -4596,14 +4599,23 @@
 
 sub symbread {
     my ($thisfn,$donotrecurse)=@_;
+    if (defined($ENV{'request.symbread.cached'})) {
+	return $ENV{'request.symbread.cached'};
+    }
 # no filename provided? try from environment
     unless ($thisfn) {
-        if ($ENV{'request.symb'}) { return &symbclean($ENV{'request.symb'}); }
+        if ($ENV{'request.symb'}) {
+	    $ENV{'request.symbread.cached'}=&symbclean($ENV{'request.symb'});
+	    return $ENV{'request.symbread.cached'};
+	}
 	$thisfn=$ENV{'request.filename'};
     }
 # is that filename actually a symb? Verify, clean, and return
     if ($thisfn=~/\_\_\_\d+\_\_\_(.*)$/) {
-	if (&symbverify($thisfn,$1)) { return &symbclean($thisfn); }
+	if (&symbverify($thisfn,$1)) {
+	    $ENV{'request.symbread.cached'}=&symbclean($thisfn);
+	    return $ENV{'request.symbread.cached'};
+	}
     }
     $thisfn=declutter($thisfn);
     my %hash;
@@ -4624,6 +4636,7 @@
            unless ($syval=~/\_\d+$/) {
 	       unless ($ENV{'form.request.prefix'}=~/\.(\d+)\_$/) {
                   &appenv('request.ambiguous' => $thisfn);
+		  $ENV{'request.symbread.cached'}='';
                   return '';
                }    
                $syval.=$1;
@@ -4671,10 +4684,12 @@
            }
         }
         if ($syval) {
-           return &symbclean($syval.'___'.$thisfn); 
+	    $ENV{'request.symbread.cached'}=&symbclean($syval.'___'.$thisfn);
+	    return $ENV{'request.symbread.cached'};
         }
     }
     &appenv('request.ambiguous' => $thisfn);
+    $ENV{'request.symbread.cached'}='';
     return '';
 }