[LON-CAPA-cvs] cvs: loncom /interface coursecatalog.pm domainprefs.pm /lonnet/perl lonnet.pm
raeburn
raeburn at source.lon-capa.org
Mon Jul 22 21:30:45 EDT 2019
raeburn Tue Jul 23 01:30:45 2019 EDT
Modified files:
/loncom/interface coursecatalog.pm domainprefs.pm
/loncom/lonnet/perl lonnet.pm
Log:
- Course categories defined in a domain are cached for 1 hour.
- Devalidate cats cache for domain if categories changed by DC.
Index: loncom/interface/coursecatalog.pm
diff -u loncom/interface/coursecatalog.pm:1.100 loncom/interface/coursecatalog.pm:1.101
--- loncom/interface/coursecatalog.pm:1.100 Sun Jul 21 14:26:02 2019
+++ loncom/interface/coursecatalog.pm Tue Jul 23 01:30:35 2019
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler for displaying the course catalog interface
#
-# $Id: coursecatalog.pm,v 1.100 2019/07/21 14:26:02 raeburn Exp $
+# $Id: coursecatalog.pm,v 1.101 2019/07/23 01:30:35 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -91,24 +91,23 @@
$r->print(&Apache::loncommon::end_page());
return OK;
}
- my %domconfig =
- &Apache::lonnet::get_dom('configuration',['coursecategories'],$codedom);
+ my $crscats = &Apache::lonnet::get_dom_cats($codedom);
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($codedom);
my $knownuser = &user_is_known();
my $canviewall = &canview_all($knownuser,$codedom);
my ($cathash,$cattype);
- if (ref($domconfig{'coursecategories'}) eq 'HASH') {
- $cathash = $domconfig{'coursecategories'}{'cats'};
- if ($knownuser || $canviewall) {
- $cattype = $domconfig{'coursecategories'}{'auth'};
- } else {
- $cattype = $domconfig{'coursecategories'}{'unauth'};
- }
- if ($cattype eq '') {
- $cattype = 'std';
- }
+ if (ref($crscats) eq 'HASH') {
+ %{$cathash} = %{$crscats};
} else {
$cathash = {};
+ }
+ if ($knownuser || $canviewall) {
+ $cattype = $domdefaults{'catauth'};
+ } else {
+ $cattype = $domdefaults{'catunauth'};
+ }
+ if ($cattype eq '') {
$cattype = 'std';
}
if ($cattype eq 'none') {
@@ -120,7 +119,7 @@
if ($knownuser || $canviewall) {
$r->print('<div>'.&mt('No catalog of LON-CAPA courses/communities is provided for: [_1]',$domdesc).'</div>');
} else {
- if ($domconfig{'coursecategories'}{'auth'} eq 'none') {
+ if ($domdefaults{'catauth'} eq 'none') {
$r->print('<div>'.&mt('No catalog of LON-CAPA courses/communities is provided for: [_1]',$domdesc).'</div>');
} else {
$r->print('<div>'.&mt('The catalog of LON-CAPA courses/communities provided for: "[_1]" is only available to users who are logged in.',$domdesc).'</div>');
@@ -130,7 +129,7 @@
return OK;
}
- my $cnum;
+ my $cnum;
if ($cattype eq 'codesrch') {
my ($uniquecode,$codemsg,$brtext);
if ($env{'form.uniquecode'}) {
@@ -251,7 +250,7 @@
$toplevelstr =~ s/,$//;
$maxdepthstr =~ s/,$//;
}
- &validate_input($codedom,\@cats,\%maxd,$domconfig{'coursecategories'});
+ &validate_input($codedom,\@cats,\%maxd,$cathash);
my ($numtitles, at codetitles);
if (($env{'form.coursenum'} ne '') && ($knownuser)) {
&course_details($r,$codedom,$formname,$domdesc,\@trails,\%allitems,\@codetitles);
@@ -393,7 +392,7 @@
}
sub validate_input {
- my ($codedom,$cats,$maxd,$configref) = @_;
+ my ($codedom,$cats,$maxd,$crscatsref) = @_;
my $currcat = '';
my $depth = 0;
if ($env{'form.catalog_maxdepth'} ne '') {
@@ -519,12 +518,8 @@
if (exists($env{'form.currcat_0'})) {
unless ($env{'form.currcat_0'} =~ /^(instcode|communities|placement)\Q::0\E$/) {
if ($env{'form.currcat_0'} =~ /^.+\Q::0\E$/) {
- if (ref($configref) eq 'HASH') {
- if (ref($configref->{'cats'}) eq 'HASH') {
- unless (exists($configref->{'cats'}->{$env{'form.currcat_0'}})) {
- delete($env{'form.currcat_0'});
- }
- } else {
+ if (ref($crscatsref) eq 'HASH') {
+ unless (exists($crscatsref->{$env{'form.currcat_0'}})) {
delete($env{'form.currcat_0'});
}
} else {
@@ -625,11 +620,9 @@
foreach my $key (keys(%currcats)) {
if ($env{'form.'.$key} eq '') {
delete($env{'form.'.$key});
- } elsif (ref($configref) eq 'HASH') {
- if (ref($configref->{'cats'}) eq 'HASH') {
- unless (exists($configref->{'cats'}->{$env{'form.'.$key}})) {
- delete($env{'form.'.$key});
- }
+ } elsif (ref($crscatsref) eq 'HASH') {
+ unless (exists($crscatsref->{$env{'form.'.$key}})) {
+ delete($env{'form.'.$key});
} else {
delete($env{'form.'.$key});
}
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.363 loncom/interface/domainprefs.pm:1.364
--- loncom/interface/domainprefs.pm:1.363 Thu Jul 18 18:28:52 2019
+++ loncom/interface/domainprefs.pm Tue Jul 23 01:30:35 2019
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.363 2019/07/18 18:28:52 raeburn Exp $
+# $Id: domainprefs.pm,v 1.364 2019/07/23 01:30:35 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -16895,6 +16895,10 @@
}
$resulttext .= '</ul></li>';
}
+ &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
+ if (ref($lastactref) eq 'HASH') {
+ $lastactref->{'cats'} = 1;
+ }
}
$resulttext .= '</ul>';
if ($changes{'unauth'} || $changes{'auth'}) {
@@ -19675,7 +19679,7 @@
my %thismachine;
map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
- 'directorysrch','passwdconf');
+ 'directorysrch','passwdconf','cats');
if (keys(%servers)) {
foreach my $server (keys(%servers)) {
next if ($thismachine{$server});
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1411 loncom/lonnet/perl/lonnet.pm:1.1412
--- loncom/lonnet/perl/lonnet.pm:1.1411 Thu Jul 18 18:28:58 2019
+++ loncom/lonnet/perl/lonnet.pm Tue Jul 23 01:30:44 2019
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.1411 2019/07/18 18:28:58 raeburn Exp $
+# $Id: lonnet.pm,v 1.1412 2019/07/23 01:30:44 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2721,6 +2721,26 @@
return %domdefaults;
}
+sub get_dom_cats {
+ my ($dom) = @_;
+ return unless (&domain($dom));
+ my ($cats,$cached)=&is_cached_new('cats',$dom);
+ unless (defined($cached)) {
+ my %domconfig = &get_dom('configuration',['coursecategories'],$dom);
+ if (ref($domconfig{'coursecategories'}) eq 'HASH') {
+ if (ref($domconfig{'coursecategories'}{'cats'}) eq 'HASH') {
+ %{$cats} = %{$domconfig{'coursecategories'}{'cats'}};
+ } else {
+ $cats = {};
+ }
+ } else {
+ $cats = {};
+ }
+ &Apache::lonnet::do_cache_new('cats',$dom,$cats,3600);
+ }
+ return $cats;
+}
+
sub course_portal_url {
my ($cnum,$cdom) = @_;
my $chome = &homeserver($cnum,$cdom);
More information about the LON-CAPA-cvs
mailing list