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

www lon-capa-cvs@mail.lon-capa.org
Thu, 17 Nov 2005 16:58:26 -0000


www		Thu Nov 17 11:58:26 2005 EDT

  Modified files:              
    /loncom/interface	loncommon.pm lonpreferences.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Names are cached
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.294 loncom/interface/loncommon.pm:1.295
--- loncom/interface/loncommon.pm:1.294	Tue Nov 15 17:03:05 2005
+++ loncom/interface/loncommon.pm	Thu Nov 17 11:57:54 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.294 2005/11/15 22:03:05 raeburn Exp $
+# $Id: loncommon.pm,v 1.295 2005/11/17 16:57:54 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1920,12 +1920,11 @@
 
 =cut
 
+
 ###############################################################
 sub plainname {
     my ($uname,$udom,$first)=@_;
-    my %names=&Apache::lonnet::get('environment',
-                    ['firstname','middlename','lastname','generation'],
-					 $udom,$uname);
+    my %names=&getnames($uname,$udom);
     my $name=&Apache::lonnet::format_name($names{'firstname'},
 					  $names{'middlename'},
 					  $names{'lastname'},
@@ -1956,19 +1955,7 @@
 
 sub nickname {
     my ($uname,$udom)=@_;
-    my %names;
-    if ($uname eq $env{'user.name'} &&
-	$udom eq $env{'user.domain'}) {
-	%names=('nickname'   => $env{'environment.nickname'}  ,
-		'firstname'  => $env{'environment.firstname'} ,
-		'middlename' => $env{'environment.middlename'},
-		'lastname'   => $env{'environment.lastname'}  ,
-		'generation' => $env{'environment.generation'});
-    } else {
-	%names=&Apache::lonnet::get('environment',
-				    ['nickname','firstname','middlename',
-				     'lastname','generation'],$udom,$uname);
-    }
+    my %names=&getnames($uname,$udom);
     my $name=$names{'nickname'};
     if ($name) {
        $name='"'.$name.'"'; 
@@ -1981,6 +1968,20 @@
     return $name;
 }
 
+sub getnames {
+    my ($uname,$udom)=@_;
+    my $id=$uname.':'.$udom;
+    my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
+    if ($cached) {
+	return %{$names};
+    } else {
+	my %loadnames=&Apache::lonnet::get('environment',
+                    ['firstname','middlename','lastname','generation','nickname'],
+					 $udom,$uname);
+	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
+	return %loadnames;
+    }
+}
 
 # ------------------------------------------------------------------ Screenname
 
Index: loncom/interface/lonpreferences.pm
diff -u loncom/interface/lonpreferences.pm:1.67 loncom/interface/lonpreferences.pm:1.68
--- loncom/interface/lonpreferences.pm:1.67	Tue Aug 16 12:31:09 2005
+++ loncom/interface/lonpreferences.pm	Thu Nov 17 11:57:54 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.67 2005/08/16 16:31:09 albertel Exp $
+# $Id: lonpreferences.pm,v 1.68 2005/11/17 16:57:54 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -403,7 +403,7 @@
         &Apache::lonnet::delenv('environment\.nickname');
         $message.='Reset nickname';
     }
-
+    &Apache::lonnet::devalidate_cache_new('namescache',$user.':'.$domain);
     $r->print(<<ENDVCSCREEN);
 $message
 ENDVCSCREEN
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.679 loncom/lonnet/perl/lonnet.pm:1.680
--- loncom/lonnet/perl/lonnet.pm:1.679	Tue Nov 15 17:02:58 2005
+++ loncom/lonnet/perl/lonnet.pm	Thu Nov 17 11:58:23 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.679 2005/11/15 22:02:58 raeburn Exp $
+# $Id: lonnet.pm,v 1.680 2005/11/17 16:58:23 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3937,6 +3937,7 @@
     }
     my $reply = &put('environment', \%names, $udom,$uname);
     if ($reply ne 'ok') { return 'error: '.$reply; }
+    &devalidate_cache_new('namescache',$uname.':'.$udom);
     &logthis('Success modifying user '.$udom.', '.$uname.', '.$uid.', '.
              $umode.', '.$first.', '.$middle.', '.
 	     $last.', '.$gene.' by '.