[LON-CAPA-cvs] cvs: loncom /interface lonsearchcat.pm /lonnet/perl lonnet.pm
damieng
damieng at source.lon-capa.org
Fri Jun 12 17:11:21 EDT 2015
damieng Fri Jun 12 21:11:21 2015 EDT
Modified files:
/loncom/interface lonsearchcat.pm
/loncom/lonnet/perl lonnet.pm
Log:
fixed some bugs in search UI, reduced sleeps for speed optimization in search and general network communication, reduced some timeouts
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.344 loncom/interface/lonsearchcat.pm:1.345
--- loncom/interface/lonsearchcat.pm:1.344 Sun Dec 14 22:11:03 2014
+++ loncom/interface/lonsearchcat.pm Fri Jun 12 21:11:07 2015
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.344 2014/12/14 22:11:03 raeburn Exp $
+# $Id: lonsearchcat.pm,v 1.345 2015/06/12 21:11:07 damieng Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -78,6 +78,7 @@
use Apache::lonindexer();
use Apache::lonwishlist();
use LONCAPA;
+use Time::HiRes qw(sleep);
######################################################################
######################################################################
@@ -143,7 +144,7 @@
## this once, so the pause indicator is deleted
##
if (exists($env{'form.pause'})) {
- sleep(1);
+ Time::HiRes::sleep(0.1);
delete($env{'form.pause'});
}
##
@@ -2050,17 +2051,15 @@
&Apache::lonnet::logthis(&Apache::lonmysql::get_error());
return;
}
+ # update results
+ my $newloc = '/adm/searchcat?phase=results&persistent_db_id='.
+ $env{'form.persistent_db_id'};
my $js =<<END;
<script type="text/javascript">
-// <![CDATA[
- function change_sort() {
- var newloc = "/adm/searchcat?phase=results";
- newloc += "&persistent_db_id=$env{'form.persistent_db_id'}";
- newloc += "&sortby=";
- newloc += document.forms.statusform.elements.sortby.value;
- parent.resultsframe.location= newloc;
- }
-// ]]>
+ var frame = parent.resultsframe;
+ var frameDoc = frame.document;
+ if (frameDoc.readyState == 'complete')
+ frame.location = "$newloc";
</script>
END
@@ -2228,8 +2227,24 @@
$r->rflush();
}
+sub reload_result_frame {
+ my ($r) = @_;
+ my $newloc = '/adm/searchcat?phase=results&persistent_db_id='.
+ $env{'form.persistent_db_id'};
+ $r->print(<<SCRIPT);
+<script type="text/javascript">
+ var frame = parent.resultsframe;
+ var frameDoc = frame.document;
+ if (frameDoc.readyState == 'complete')
+ frame.location = "$newloc";
+</script>
+SCRIPT
+
+ $r->rflush();
+}
+
{
- my $max_time = 300; # seconds for the search to complete
+ my $max_time = 60; # seconds for the search to complete
my $start_time = 0;
my $last_time = 0;
@@ -2410,6 +2425,7 @@
##
## Prepare for the big loop.
my $hitcountsum;
+ my $oldhitcountsum;
my %matches;
my $server;
my $status;
@@ -2456,7 +2472,7 @@
&update_status($r,
&mt('waiting on [_1]',join(' ',keys(%Server_status))));
}
- sleep(1);
+ Time::HiRes::sleep(0.1);
}
#
# Loop through the servers we have contacted but do not
@@ -2532,7 +2548,13 @@
delete($Server_status{$server});
}
last if ($connection->aborted());
- &update_count_status($r,$hitcountsum);
+ if ($oldhitcountsum < $hitcountsum) {
+ &update_count_status($r,$hitcountsum);
+ if ($hitcountsum <= $env{'form.show'}) {
+ reload_result_frame($r);
+ }
+ $oldhitcountsum = $hitcountsum;
+ }
}
last if ($connection->aborted());
&update_seconds($r);
@@ -2626,6 +2648,8 @@
if ($env{'form.catalogmode'} eq 'import') {
if (! tie(%groupsearch_db,'GDBM_File',$diropendb,
&GDBM_WRCREAT(),0640)) {
+ # NOTE: this can happen when a previous request to searchcat?phase=results gets interrupted
+ # (%groupsearch_db is not untied)
$r->print('<p class="LC_error">'.
&mt('Unable to save import results.').
'</p>'.
@@ -2634,6 +2658,10 @@
$r->rflush();
return;
}
+ # untie %groupsearch_db if the connection gets aborted before the end
+ $r->register_cleanup(sub {
+ untie %groupsearch_db if (tied(%groupsearch_db));
+ });
}
##
## Prepare the table for querying
@@ -2775,8 +2803,7 @@
);
if ($total_results == 0) {
- $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2" />'.
- '<p class="LC_info">'.&mt('There are currently no results.').'</p>'.
+ $r->print('<p class="LC_info">'.&mt('There are currently no results.').'</p>'.
"</form>".
&Apache::loncommon::end_page());
return;
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1287 loncom/lonnet/perl/lonnet.pm:1.1288
--- loncom/lonnet/perl/lonnet.pm:1.1287 Thu May 21 23:40:25 2015
+++ loncom/lonnet/perl/lonnet.pm Fri Jun 12 21:11:20 2015
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.1287 2015/05/21 23:40:25 raeburn Exp $
+# $Id: lonnet.pm,v 1.1288 2015/06/12 21:11:20 damieng Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -101,11 +101,12 @@
use LONCAPA::Configuration;
use LONCAPA::lonmetadata;
use LONCAPA::Lond;
+use Time::HiRes qw(sleep);
use File::Copy;
my $readit;
-my $max_connection_retries = 10; # Or some such value.
+my $max_connection_retries = 20; # Or some such value.
require Exporter;
@@ -375,7 +376,7 @@
my $lockfile=$peerfile.".lock";
while (-e $lockfile) { # Need to wait for the lockfile to disappear.
- sleep(1);
+ Time::HiRes::sleep(0.1);
}
# At this point, either a loncnew parent is listening or an old lonc
# or loncnew child is listening so we can connect or everything's dead.
@@ -393,7 +394,7 @@
} else {
&create_connection(&hostname($server),$server);
}
- sleep(1); # Try again later if failed connection.
+ Time::HiRes::sleep(0.1); # Try again later if failed connection.
}
my $answer;
if ($client) {
@@ -486,7 +487,7 @@
close($dfh);
}
}
- sleep 2;
+ sleep 1;
my $wcmd='';
{
my $dfh;
@@ -7678,7 +7679,7 @@
my $replyfile=LONCAPA::tempdir().$queryid;
my $reply='';
for (1..100) {
- sleep 2;
+ Time::HiRes::sleep(0.2);
if (-e $replyfile.'.end') {
if (open(my $fh,$replyfile)) {
$reply = join('',<$fh>);
@@ -9521,9 +9522,9 @@
my $tries = 0;
my $gotlock = &newput('file_permissions',$lockhash,$domain,$user);
- while (($gotlock ne 'ok') && $tries <3) {
+ while (($gotlock ne 'ok') && $tries < 10) {
$tries ++;
- sleep 1;
+ Time::HiRes::sleep(0.1);
$gotlock = &newput('file_permissions',$lockhash,$domain,$user);
}
if ($gotlock eq 'ok') {
More information about the LON-CAPA-cvs
mailing list