--- loncom/interface/Attic/lonspreadsheet.pm 2001/03/12 18:27:46 1.43 +++ loncom/interface/Attic/lonspreadsheet.pm 2001/03/13 15:50:47 1.44 @@ -4,7 +4,7 @@ # 11/11,11/15,11/27,12/04,12/05,12/06,12/07, # 12/08,12/09,12/11,12/12,12/15,12/16,12/18,12/19,12/30, # 01/01/01,02/01,03/01,19/01,20/01,22/01, -# 03/05,03/08,03/10,03/12 Gerd Kortemeyer +# 03/05,03/08,03/10,03/12,03/13 Gerd Kortemeyer package Apache::lonspreadsheet; @@ -18,6 +18,12 @@ use GDBM_File; use HTML::TokeParser; # +# Caches for previously calculated spreadsheets +# + +my %oldsheets; + +# # Cache for stores of an individual user # @@ -1482,14 +1488,94 @@ sub loadrows { # sub exportsheet { - - my ($uname,$udom,$stype,$usymb,$fn)=@_; + my ($uname,$udom,$stype,$usymb,$fn)=@_; + my @exportarr=(); +# +# Check if cached +# + my $key=$uname.':'.$udom.':'.$stype.':'.$usymb; + my $found=''; + + if ($oldsheets{$key}) { + map { + my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_); + if ($name eq $fn) { + $found=$value; + } + } split(/\_\_\_\&\_\_\_/,$oldsheets{$key}); + } + + if ($found) { +# +# Return what was cached +# + @exportarr=split(/\_\_\_\;\_\_\_/,$found); + + } else { +# +# Not cached +# my $thissheet=&makenewsheet($uname,$udom,$stype,$usymb); &readsheet($thissheet,$fn); &updatesheet($thissheet); &loadrows($thissheet); - &calcsheet($thissheet); - return &exportdata($thissheet); + &calcsheet($thissheet); + @exportarr=&exportdata($thissheet); +# +# Store now +# + my $cid=$ENV{'request.course.id'}; + my $current=&Apache::lonnet::reply('get:'. + $ENV{'course.'.$cid.'.domain'}.':'. + $ENV{'course.'.$cid.'.num'}. + ':nohist_calculatedsheets:'. + &Apache::lonnet::escape($key), + $ENV{'course.'.$cid.'.home'}); + my %currentlystored=(); + unless ($current=~/^error\:/) { + map { + my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_); + $currentlystored{$name}=$value; + } split(/\_\_\_\&\_\_\_/,&Apache::lonnet::unescape($current)); + } + $currentlystored{$fn}=join('___;___',@exportarr); + + my $newstore=''; + map { + if ($newstore) { $newstore.='___&___'; } + $newstore.=$_.'___=___'.$currentlystored{$_}; + } keys %currentlystored; + &Apache::lonnet::reply('put:'. + $ENV{'course.'.$cid.'.domain'}.':'. + $ENV{'course.'.$cid.'.num'}. + ':nohist_calculatedsheets:'. + &Apache::lonnet::escape($key).'='. + &Apache::lonnet::escape($newstore), + $ENV{'course.'.$cid.'.home'}); + } + return @exportarr; +} + +# ===================================================== Calculated sheets cache +# +# Load all previously cached spreadsheets for this course +# + +sub cachedsheets { + my $cid=$ENV{'request.course.id'}; + my $reply=&Apache::lonnet::reply('dump:'. + $ENV{'course.'.$cid.'.domain'}.':'. + $ENV{'course.'.$cid.'.num'}. + ':nohist_calculatedsheets', + $ENV{'course.'.$cid.'.home'}); + undef %oldsheets; + unless ($reply=~/^error\:/) { + map { + my ($name,$value)=split(/\=/,$_); + $oldsheets{&Apache::lonnet::unescape($name)} + =&Apache::lonnet::unescape($value); + } split(/\&/,$reply); + } } # ================================================================ Main handler @@ -1660,10 +1746,13 @@ ENDSCRIPT $r->print(&hiddenfield('ufn',&getfilename($asheet))); +# ----------------------------------------------------------- Get cached sheets + + &cachedsheets(); # ----------------------------------------------------- Update sheet, load rows - $r->print("Loaded sheet, updating rows ...
\n"); + $r->print("Loaded sheet(s), updating rows ...
\n"); $r->rflush(); &updatesheet($asheet); @@ -1695,19 +1784,3 @@ ENDSCRIPT 1; __END__ - - - - - - - - - - - - - - - -