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

www www at source.lon-capa.org
Wed Feb 15 16:56:26 EST 2012


www		Wed Feb 15 21:56:26 2012 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Bug #6559: cache for navmaps to have acceptable response times when
  using timed assignments (interval)
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1152 loncom/lonnet/perl/lonnet.pm:1.1153
--- loncom/lonnet/perl/lonnet.pm:1.1152	Wed Feb  1 00:18:29 2012
+++ loncom/lonnet/perl/lonnet.pm	Wed Feb 15 21:56:25 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1152 2012/02/01 00:18:29 raeburn Exp $
+# $Id: lonnet.pm,v 1.1153 2012/02/15 21:56:25 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3858,6 +3858,25 @@
 
 # ----------------------------------------------------------- Interval timing 
 
+{
+# Caches needed for speedup of navmaps
+# We don't want to cache this for very long at all (5 seconds at most)
+# 
+# The user for whom we cache
+my $cachedkey='';
+# The cached times for this user
+my %cachedtimes=();
+# When this was last done
+my $cachedtime=();
+
+sub load_all_first_access {
+   my ($uname,$udom)=@_;
+   if (($cachedkey eq $uname.':'.$udom) && (abs($cachedtime-time)<5)) { return; };
+   $cachedtime=time;
+   $cachedkey=$uname.':'.$udom;
+   %cachedtimes=&dump('firstaccesstimes',$udom,$uname);
+}
+
 sub get_first_access {
     my ($type,$argsymb)=@_;
     my ($symb,$courseid,$udom,$uname)=&whichuser();
@@ -3870,8 +3889,8 @@
     } else {
 	$res=$symb;
     }
-    my %times=&get('firstaccesstimes',["$courseid\0$res"],$udom,$uname);
-    return $times{"$courseid\0$res"};
+    &load_all_first_access($uname,$udom);
+    return $cachedtimes{"$courseid\0$res"};
 }
 
 sub set_first_access {
@@ -3885,13 +3904,14 @@
     } else {
 	$res=$symb;
     }
+    $cachedkey='';
     my $firstaccess=&get_first_access($type,$symb);
     if (!$firstaccess) {
 	return &put('firstaccesstimes',{"$courseid\0$res"=>time},$udom,$uname);
     }
     return 'already_set';
 }
-
+}
 # --------------------------------------------- Set Expire Date for Spreadsheet
 
 sub expirespread {




More information about the LON-CAPA-cvs mailing list