--- loncom/lonnet/perl/lonnet.pm 2012/02/01 00:18:29 1.1152 +++ loncom/lonnet/perl/lonnet.pm 2012/02/15 21:56:25 1.1153 @@ -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 @@ sub get_domain_roles { # ----------------------------------------------------------- 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 @@ sub get_first_access { } 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 @@ sub set_first_access { } 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 {