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

raeburn raeburn at source.lon-capa.org
Tue Dec 20 17:40:06 EST 2011


raeburn		Tue Dec 20 22:40:06 2011 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Improve efficiency by caching information for all slots in course.
  - New routines:
   &get_reservable_slots() -- information for current user about student schedulable
        slots opening in the future, which will be available to the user.
        (%remembered stores data for duration of request).
   &get_course_slots() - retrieve contents of 'slots' db from cache or lonnet::dump().
   &devalidate_slots_cache() -- devalidates 'allslots' cache.
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1149 loncom/lonnet/perl/lonnet.pm:1.1150
--- loncom/lonnet/perl/lonnet.pm:1.1149	Wed Dec 14 21:03:53 2011
+++ loncom/lonnet/perl/lonnet.pm	Tue Dec 20 22:40:06 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1149 2011/12/14 21:03:53 raeburn Exp $
+# $Id: lonnet.pm,v 1.1150 2011/12/20 22:40:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -9399,6 +9399,49 @@
     }
     return $slotinfo{$which};
 }
+
+sub get_reservable_slots {
+    my ($cnum,$cdom,$uname,$udom) = @_;
+    my $now = time;
+    my $reservable_info;
+    my $key=join("\0",'reservableslots',$cdom,$cnum,$uname,$udom);
+    if (exists($remembered{$key})) {
+        $reservable_info = $remembered{$key};
+    } else {
+        my %resv;
+        ($resv{'now_order'},$resv{'now'},$resv{'future_order'},$resv{'future'}) =
+        &Apache::loncommon::get_future_slots($cnum,$cdom,$now);
+        $reservable_info = \%resv;
+        $remembered{$key} = $reservable_info;
+    }
+    return $reservable_info;
+}
+
+sub get_course_slots {
+    my ($cnum,$cdom) = @_;
+    my $hashid=$cnum.':'.$cdom;
+    my ($result,$cached) = &Apache::lonnet::is_cached_new('allslots',$hashid);
+    if (defined($cached)) {
+        if (ref($result) eq 'HASH') {
+            return %{$result};
+        }
+    } else {
+        my %slots=&Apache::lonnet::dump('slots',$cdom,$cnum);
+        my ($tmp) = keys(%slots);
+        if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
+            &Apache::lonnet::do_cache_new('allslots',$hashid,\%slots,600);
+            return %slots;
+        }
+    }
+    return;
+}
+
+sub devalidate_slots_cache {
+    my ($cnum,$cdom)=@_;
+    my $hashid=$cnum.':'.$cdom;
+    &devalidate_cache_new('allslots',$hashid);
+}
+
 # ------------------------------------------------- Update symbolic store links
 
 sub symblist {




More information about the LON-CAPA-cvs mailing list