From 1217f130fa8890a3c12fb4e91e3df52361218e95 Mon Sep 17 00:00:00 2001 From: Arne Georg Gleditsch Date: Fri, 29 Feb 2008 00:13:20 +0100 Subject: Expanded cache fragment size, adjustet ajax redirection to take line numbers into account. --- lib/LXRng/Web.pm | 185 ++++++++++++++++++++++++++-------------------------- tmpl/ajax_redir.tt2 | 13 ++++ 2 files changed, 107 insertions(+), 91 deletions(-) create mode 100644 tmpl/ajax_redir.tt2 diff --git a/lib/LXRng/Web.pm b/lib/LXRng/Web.pm index b8e06d5..c9acc71 100644 --- a/lib/LXRng/Web.pm +++ b/lib/LXRng/Web.pm @@ -38,7 +38,7 @@ use File::Path qw(mkpath); use POSIX qw(waitpid); # Cache must be purged if this is changed. -use constant FRAGMENT_SIZE => 250; +use constant FRAGMENT_SIZE => 1000; use vars qw($has_gzip_io); eval { require PerlIO::gzip; $has_gzip_io = 1; }; @@ -77,101 +77,101 @@ sub print_markedup_file { or die $template->error(); return; } - else { - my $line = 0; - my $focus = 1; - my $fline = $context->param('line'); - - $focus = $fline < FRAGMENT_SIZE if defined($fline); - - my $shaid = sha1_hex(join("\0", $node->name, $node->revision, - $context->release)); - my $cfile; - $shaid =~ s,^(..)(..),$1/$2/,; - $shaid .= '_2'; # Cache file format generation indicator - $cfile = $context->config->{'cache'}.'/'.$shaid - if exists $context->config->{'cache'}; - - if ($cfile and -e "$cfile/.complete") { - print("
"); - while (-r "$cfile/$line") { - print("
");
-		if ($focus) {
-		    open(my $cache, '<', "$cfile/$line");
-		    my $buf;
-		    while (read($cache, $buf, 16384) > 0) {
-			print($buf);
-		    }
-		    close($cache);
-		}
-		else {
-		    print("\n" x FRAGMENT_SIZE);
-		}
-		print("
"); - $line += FRAGMENT_SIZE; - if (defined($fline)) { - $focus = ($line <= ($fline + 100) - and $line > ($fline - FRAGMENT_SIZE)); + my $line = 0; + my $focus = 1; + my $fline = $context->param('line'); + + $focus = $fline < FRAGMENT_SIZE if defined($fline); + + my $shaid = sha1_hex(join("\0", $node->name, $node->revision, + $context->release)); + my $cfile; + $shaid =~ s,^(..)(..),$1/$2/,; + $shaid .= '_3'; # Cache file format generation indicator + $cfile = $context->config->{'cache'}.'/'.$shaid + if exists $context->config->{'cache'}; + + if ($cfile and -e "$cfile/.complete") { + print("
"); + while (-r "$cfile/$line") { + print("
");
+	    if ($focus) {
+		open(my $cache, '<', "$cfile/$line");
+		my $buf;
+		while (read($cache, $buf, 16384) > 0) {
+		    print($buf);
 		}
+		close($cache);
 	    }
-	    print("
\n"); - } - else { - my $cache; - if ($cfile) { - mkpath($cfile, 0, 0777); - open($cache, '>', "$cfile/0"); + else { + print("\n" x FRAGMENT_SIZE); } - my $handle = $node->handle(); - LXRng::Lang->init($context); - my $lang = LXRng::Lang->new($node); - my $parse = LXRng::Parse::Simple->new($handle, 8, - @{$lang->parsespec}); - my $markup = LXRng::Markup::File->new('context' => $context); - my $subst = $lang->markuphandlers($context, $node, $markup); - - print("
". - "
");
-	    while (1) {
-		my @frags = map { split(/(?<=\n)/, $_) }
-		$markup->markupfile($subst, $parse);
-		last unless @frags;
-		foreach my $f (@frags) {
-		    print($f) if $focus;
-		    print($cache $f) if $cache;
-		    if ($f =~ /\n$/s) {
-			$line++;
-			if ($line % FRAGMENT_SIZE == 0) {
-			    print("\n" x FRAGMENT_SIZE)
-				unless $focus;
-			    if (defined($fline)) {
-				$focus = ($line <= ($fline + 100)
-					  and $line > ($fline - FRAGMENT_SIZE));
-			    }
-			    print("
". - "
");
-			    if ($cache) {
-				close($cache);
-				open($cache, '>', "$cfile/$line");
-			    }
-			}
+	    print("
"); + $line += FRAGMENT_SIZE; + + if (defined($fline)) { + $focus = ($line <= ($fline + 100) + and $line > ($fline - FRAGMENT_SIZE)); + } + } + print("
\n"); + return "use:".$shaid; + } + + my $cache; + if ($cfile) { + mkpath($cfile, 0, 0777); + open($cache, '>', "$cfile/0"); + } + my $handle = $node->handle(); + LXRng::Lang->init($context); + my $lang = LXRng::Lang->new($node); + my $parse = LXRng::Parse::Simple->new($handle, 8, + @{$lang->parsespec}); + my $markup = LXRng::Markup::File->new('context' => $context); + my $subst = $lang->markuphandlers($context, $node, $markup); + + print("
". + "
");
+    while (1) {
+	my @frags = map { split(/(?<=\n)/, $_) }
+	$markup->markupfile($subst, $parse);
+	last unless @frags;
+	foreach my $f (@frags) {
+	    print($f) if $focus;
+	    print($cache $f) if $cache;
+	    if ($f =~ /\n$/s) {
+		$line++;
+		if ($line % FRAGMENT_SIZE == 0) {
+		    print("\n" x FRAGMENT_SIZE)
+			unless $focus;
+		    if (defined($fline)) {
+			$focus = ($line <= ($fline + 100)
+				  and $line > ($fline - FRAGMENT_SIZE));
+		    }
+		    print("
". + "
");
+		    if ($cache) {
+			close($cache);
+			open($cache, '>', "$cfile/$line");
 		    }
 		}
 	    }
-	    print("
\n"); - if ($cache) { - close($cache); - open($cache, '>', "$cfile/.complete"); - close($cache); - } } - return $shaid; } + print("
\n"); + if ($cache) { + close($cache); + open($cache, '>', "$cfile/.complete"); + close($cache); + } + + return "gen:".$shaid; } sub print_error { @@ -225,15 +225,18 @@ sub source { $pjx->js_encode_function('escape'); if ($context->prefs and $context->prefs->{'navmethod'} eq 'ajax') { + print($query->header(-type => 'text/html', + -charset => 'utf-8')); if ($context->tree ne '') { my $base = $context->base_url(1); my $path = $context->vtree.'/'.$context->path; - print($query->redirect($base.'#'.$path)); + # print($query->redirect($base.'#'.$path)); + + $template->process('ajax_redir.tt2', + {'ajax_url' => $base.'#'.$path}) + or die $template->error(); } else { - print($query->header(-type => 'text/html', - -charset => 'utf-8')); - if ($context->release eq 'trees') { print_tree_list($context, $template); } diff --git a/tmpl/ajax_redir.tt2 b/tmpl/ajax_redir.tt2 new file mode 100644 index 0000000..54542bf --- /dev/null +++ b/tmpl/ajax_redir.tt2 @@ -0,0 +1,13 @@ + + + + + + + Redirecting to Ajax interface... + + -- cgit v1.2.3