[LON-CAPA-cvs] cvs: loncom /interface lonparmset.pm
albertel
lon-capa-cvs-allow@mail.lon-capa.org
Mon, 20 Aug 2007 22:32:00 -0000
albertel Mon Aug 20 18:32:00 2007 EDT
Modified files:
/loncom/interface lonparmset.pm
Log:
- BUG#5373, apache child was caching trigger data to local globals which could pollute other accesses to the same course if not deleted, switching to cleansing all cached data after eache parmset access
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.375 loncom/interface/lonparmset.pm:1.376
--- loncom/interface/lonparmset.pm:1.375 Tue Aug 7 19:56:34 2007
+++ loncom/interface/lonparmset.pm Mon Aug 20 18:31:59 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set parameters for assessments
#
-# $Id: lonparmset.pm,v 1.375 2007/08/07 23:56:34 albertel Exp $
+# $Id: lonparmset.pm,v 1.376 2007/08/20 22:31:59 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -67,16 +67,6 @@
use Apache::lonrss;
use LONCAPA qw(:DEFAULT :match);
-# --- Caches local to lonparmset
-
-my $parmhashid;
-my %parmhash;
-my $symbsid;
-my %symbs;
-my $rulesid;
-my %rules;
-
-# --- end local caches
##################################################
##################################################
@@ -119,8 +109,6 @@
sub parmval_by_symb {
my ($what,$symb,$def,$uname,$udom,$csec,$cgroup,$courseopt)=@_;
-# load caches
- &cacheparmhash();
my $useropt;
if ($uname ne '' && $udom ne '') {
@@ -167,7 +155,7 @@
# ------------------------------------------------------ third, check map parms
- my $thisparm=$parmhash{$symbparm};
+ my $thisparm=&parmhash($symbparm);
if (defined($thisparm)) { $outpar[11]=$thisparm; $result=11; }
if (defined($$courseopt{$courselevelr})) {
@@ -228,58 +216,90 @@
return ($result,@outpar);
}
-sub resetparmhash {
- $parmhashid='';
-}
-sub cacheparmhash {
- if ($parmhashid eq $env{'request.course.fn'}) { return; }
- my %parmhashfile;
- if (tie(%parmhashfile,'GDBM_File',
- $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) {
- %parmhash=%parmhashfile;
- untie %parmhashfile;
- $parmhashid=$env{'request.course.fn'};
- }
-}
-sub resetsymbcache {
- $symbsid='';
+# --- Caches local to lonparmset
+
+
+sub reset_caches {
+ &resetparmhash();
+ &resetsymbcache();
+ &resetrulescache();
}
-sub symbcache {
- my $id=shift;
- if ($symbsid ne $env{'request.course.id'}) {
- %symbs=();
+{
+ my $parmhashid;
+ my %parmhash;
+ sub resetparmhash {
+ undef($parmhashid);
+ undef(%parmhash);
}
- unless ($symbs{$id}) {
- my $navmap = Apache::lonnavmaps::navmap->new();
- if ($id=~/\./) {
- my $resource=$navmap->getById($id);
- $symbs{$id}=$resource->symb();
- } else {
- my $resource=$navmap->getByMapPc($id);
- $symbs{$id}=&Apache::lonnet::declutter($resource->src());
+
+ sub cacheparmhash {
+ if ($parmhashid eq $env{'request.course.fn'}) { return; }
+ my %parmhashfile;
+ if (tie(%parmhashfile,'GDBM_File',
+ $env{'request.course.fn'}.'_parms.db',&GDBM_READER(),0640)) {
+ %parmhash=%parmhashfile;
+ untie(%parmhashfile);
+ $parmhashid=$env{'request.course.fn'};
}
- $symbsid=$env{'request.course.id'};
}
- return $symbs{$id};
-}
-
-sub resetrulescache {
- $rulesid='';
-}
+
+ sub parmhash {
+ my ($id) = @_;
+ &cacheparmhash();
+ return $parmhash{$id};
+ }
+ }
+
+{
+ my $symbsid;
+ my %symbs;
+ sub resetsymbcache {
+ undef($symbsid);
+ undef(%symbs);
+ }
+
+ sub symbcache {
+ my $id=shift;
+ if ($symbsid ne $env{'request.course.id'}) {
+ undef(%symbs);
+ }
+ if (!$symbs{$id}) {
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if ($id=~/\./) {
+ my $resource=$navmap->getById($id);
+ $symbs{$id}=$resource->symb();
+ } else {
+ my $resource=$navmap->getByMapPc($id);
+ $symbs{$id}=&Apache::lonnet::declutter($resource->src());
+ }
+ $symbsid=$env{'request.course.id'};
+ }
+ return $symbs{$id};
+ }
+ }
-sub rulescache {
- my $id=shift;
- if ($rulesid ne $env{'request.course.id'}
- && !defined($rules{$id})) {
- my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
- %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);
- $rulesid=$env{'request.course.id'};
+{
+ my $rulesid;
+ my %rules;
+ sub resetrulescache {
+ undef($rulesid);
+ undef(%rules);
+ }
+
+ sub rulescache {
+ my $id=shift;
+ if ($rulesid ne $env{'request.course.id'}
+ && !defined($rules{$id})) {
+ my $dom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $crs = $env{'course.'.$env{'request.course.id'}.'.num'};
+ %rules=&Apache::lonnet::dump('parmdefactions',$dom,$crs);
+ $rulesid=$env{'request.course.id'};
+ }
+ return $rules{$id};
}
- return $rules{$id};
}
sub preset_defaults {
@@ -345,7 +365,6 @@
# - new type
# - username
# - userdomain
-
my %recstack;
sub storeparm_by_symb {
my ($symb,$spnam,$snum,$nval,$ntype,$uname,$udom,$csec,$recflag,$cgroup)=@_;
@@ -2990,7 +3009,6 @@
$data{'realm_type'} = 'folder';
$data{'realm_title'} = &Apache::lonnet::gettitle($data{'realm'});
($data{'realm_exists'}) = &Apache::lonnet::is_on_map($data{'realm'});
- &Apache::lonnet::logthis($1." siad ". $data{'realm_exists'} );
} elsif ($middle) {
$data{'realm'} = $middle;
$data{'realm_type'} = 'symb';
@@ -3953,14 +3971,15 @@
Main handler. Calls &assessparms and &crsenv subroutines.
=cut
+
##################################################
##################################################
-# use Data::Dumper;
-
sub handler {
my $r=shift;
+ &reset_caches();
+
if ($r->header_only) {
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
@@ -3995,10 +4014,6 @@
$r->send_http_header;
- # id numbers can change on re-ordering of folders
-
- &resetsymbcache();
-
#
# Main switch on form.action and form.state, as appropriate
#
@@ -4067,6 +4082,8 @@
}
return HTTP_NOT_ACCEPTABLE;
}
+ &reset_caches();
+
return OK;
}