git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 10/10] gitweb: Show appropriate "Generating..." page when regenerating cache (WIP)

From
Jakub Narebski <jnareb@gmail.com>
Date
Jan 23, 2010, 00:27 UTC
Message-ID
<f4660e9c7ffdb4a62da0c56703de002c9df3b598.1264198194.git.jnareb@gmail.com>
In-Reply-To
<1263432185-21334-10-git-send-email-warthog9@eaglescrag.net>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This patch, as you can see, lack proper commit message: it is work in
progress.

Contrary to the patch by J.H. the subroutine that is responsible for doing "Generating..." progress info / activity indicator is in gitweb.perl, and not in cache.pm. Also it does not use not declared nor defined $title variable ;-)

Compared with original patch by J.H. gitweb prints generating info in more restricted set of situations; the set of actions where gitweb does not generate activity indicator is larger. We could probably provide activity indicator also for (possibly) non-HTML output, like 'blob_plain' or 'patches', provided that 'User-Agent' denotes that we are using web browser.

In the future we would probably want Ajax-y JavaScript-based activity indicator, without need for busy-wait.

NOTE that I have not tested that it works, only that it should not contain syntax errors...

 gitweb/cache.pm    |   32 ++++++++++++++++++++-
 gitweb/gitweb.perl |   75 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 104 insertions(+), 3 deletions(-)
diff --git a/gitweb/cache.pm b/gitweb/cache.pm
index 1adf467..2c7be3a 100644
--- a/gitweb/cache.pm
+++ b/gitweb/cache.pm
@@ -63,7 +63,8 @@ sub new {
 	$self = bless($self, $class);
 
 	my ($root, $depth, $ns);
-	my ($expires_min, $expires_max, $increase_factor, $check_load);
+	my ($expires_min, $expires_max, $increase_factor,
+	    $check_load, $generating_info);
 	if (defined $p_options_hash_ref) {
 		$root  = $p_options_hash_ref->{'cache_root'};
 		$depth = $p_options_hash_ref->{'cache_depth'};
@@ -76,6 +77,7 @@ sub new {
 			$p_options_hash_ref->{'expires_max'};
 		$increase_factor = $p_options_hash_ref->{'expires_factor'};
 		$check_load      = $p_options_hash_ref->{'check_load'};
+		$generating_info = $p_options_hash_ref->{'generating_info'};
 	}
 	$root  = $DEFAULT_CACHE_ROOT  unless defined($root);
 	$depth = $DEFAULT_CACHE_DEPTH unless defined($depth);
@@ -92,6 +94,7 @@ sub new {
 	$self->set_expires_max($expires_max);
 	$self->set_increase_factor($increase_factor);
 	$self->set_check_load($check_load);
+	$self->set_generating_info($generating_info);
 
 	return $self;
 }
@@ -186,6 +189,18 @@ sub set_check_load {
 	$self->{'_Check_Load'} = $sub;
 }
 
+sub get_generating_info {
+	my ($self) = @_;
+
+	return $self->{'_Generating_Info'};
+}
+
+sub set_generating_info {
+	my ($self, $sub) = @_;
+
+	$self->{'_Generating_Info'} = $sub;
+}
+
 # ......................................................................
 
 sub get_expires_in {
@@ -203,6 +218,12 @@ sub get_expires_in {
 	return $expires_in;
 }
 
+sub generating_info {
+	if (defined $self->get_generating_info()) {
+		$self->get_generating_info()->($self, @_);
+	}
+}
+
 # ----------------------------------------------------------------------
 # (private) utility functions and methods
 
@@ -434,6 +455,9 @@ sub compute {
 		# acquired writers lock
 		my $pid = fork() if $data;
 		if (!defined $pid || $pid) {
+			# provide "generating page..." info if there is no stale data to serve
+			$self->generating_info($p_key, $lock_fh)
+				unless ($data);
 			# parent, or didn't fork
 			$data = $p_coderef->($self, $p_key);
 			$self->set($p_key, $data);
@@ -451,8 +475,12 @@ sub compute {
 			;
 		}
 	} else {
+		# some else process is (re)generating cache
 		if (!defined $data) {
-			# get readers lock if there is no stale data to serve
+			# there is no stale data to serve
+			# provide "generating page..." info
+			$self->generating_info($p_key, $lock_fh);
+			# get readers lock
 			flock($lock_fh, LOCK_SH);
 			$data = $self->restore($self->get_namespace(), $p_key);
 		}
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 0394dc8..cb46b8c 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -13,7 +13,7 @@ use CGI qw(:standard :escapeHTML -nosticky);
 use CGI::Util qw(unescape);
 use CGI::Carp qw(fatalsToBrowser);
 use Encode;
-use Fcntl ':mode';
+use Fcntl qw(:mode :flock);
 use File::Find qw();
 use File::Basename qw(basename);
 binmode STDOUT, ':utf8';
@@ -1023,6 +1023,7 @@ if ($caching_enabled) {
 		'cache_root'  => '/tmp/cache',
 		'cache_depth' => 2,
 		'expires_in'  => 20, # in seconds
+		'generating_info' => \&git_generating_data_html,
 	});
 	cache_fetch($cache, $action);
 } else {
@@ -3215,6 +3216,78 @@ sub blob_contenttype {
 ## ======================================================================
 ## functions printing HTML: header, footer, error page
 
+sub git_generating_data_html {
+	my ($cache, $key, $lock_fh) = @_;
+
+	if ($action eq 'atom' || $action eq 'rss' || $action eq 'opml' || # feeds
+	    $action eq 'blob_plain' || # unknown mimetype
+	    $action eq 'commitdiff_plain' || # text/plain
+	    $action eq 'patch' || $action eq 'patches' || # text/plain
+	    $action eq 'snapshot') { # binary
+		return;
+	}
+
+	my $title = "[Generating...] $site_name";
+	if (defined $project) {
+		$title .= " - " . to_utf8($project);
+		if (defined $action) {
+			$title .= "/$action";
+			if (defined $file_name) {
+				$title .= " - " . esc_path($file_name);
+				if ($action eq "tree" && $file_name !~ m|/$|) {
+					$title .= "/";
+				}
+			}
+		}
+	}
+
+	my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
+	print STDOUT $cgi->header(-type => 'text/html', -charset => 'utf-8',
+	                          -status=> '200 OK', -expires => 'now');
+	print STDOUT <<"EOF";
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
+<!-- git web interface version $version -->
+<!-- git core binaries version $git_version -->
+<head>
+<meta http-equiv="content-type" content="text/html; charset=utf-8" />
+<meta http-equiv="refresh" content="0" />
+<meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version" />
+<meta name="robots" content="noindex, nofollow" />
+<title>$title</title>
+</head>
+<body>
+EOF
+	print STDOUT 'Generating..';
+
+	my $ready;
+	my ($wait, $wait_step, $wait_max); # in seconds
+	$wait = 0;
+	$wait_step = 2;
+	$wait_max = 20;
+	$| = 1; # autoflush
+	do {
+		print STDOUT '.';
+
+		sleep $wait_step if ($wait > 0);
+		$wait += $wait_step;
+
+		$ready = flock($lock_fh, LOCK_SH|LOCK_NB)
+			if $lock_fh;
+
+	} while (!$ready && ($wait < $wait_max));
+
+	print STDOUT <<"EOF";
+
+</body>
+</html>
+EOF
+	#exit 0;
+	return;
+}
+
 sub git_header_html {
 	my $status = shift || "200 OK";
 	my $expires = shift;
-- 
1.6.6.1
Previous: Jakub NarebskiNext: Petr Baudis
Message 26 of 60 in “Gitweb caching v5”
  1. 0/9 Gitweb caching v5John 'Warthog9' Hawley, Jan 14, 2010
  2. 1/9 gitweb: Load checkingJohn 'Warthog9' Hawley, Jan 14, 2010
  3. 2/9 gitweb: change die_error to take "extra" argument for extended die informationJohn 'Warthog9' Hawley, Jan 14, 2010
  4. 3/9 gitweb: Add option to force version matchJohn 'Warthog9' Hawley, Jan 14, 2010
  5. 4/9 gitweb: Makefile improvementsJohn 'Warthog9' Hawley, Jan 14, 2010
  6. 5/9 gitweb: add a get function to compliment print_local_timeJohn 'Warthog9' Hawley, Jan 14, 2010
  7. 6/9 gitweb: add a get function to compliment print_sort_thJohn 'Warthog9' Hawley, Jan 14, 2010
  8. 7/9 gitweb: cleanup error message produced by undefined $site_headerJohn 'Warthog9' Hawley, Jan 14, 2010
  9. 8/9 gitweb: Convert output to using indirect file handleJohn 'Warthog9' Hawley, Jan 14, 2010
  10. 9/9 gitweb: File based caching layer (from git.kernel.org)John 'Warthog9' Hawley, Jan 14, 2010
  11. Jakub NarebskiJan 16, 2010
  12. 00/10 gitweb: Simple file based output cachingJakub Narebski, Jan 23, 2010
  13. J.H.Jan 23, 2010
  14. 11/10 gitweb: Ajax-y "Generating..." page when regenerating cache (WIP)Jakub Narebski, Jan 24, 2010
  15. J.H.Feb 6, 2010
  16. Jakub NarebskiFeb 6, 2010
  17. Jakub NarebskiFeb 7, 2010
  18. 02/10 gitweb: href(..., -path_info => 0|1)Jakub Narebski, Jan 23, 2010
  19. 03/10 gitweb/cache.pm - Very simple file based cachingJakub Narebski, Jan 23, 2010
  20. 04/10 gitweb/cache.pm - Stat-based cache expirationJakub Narebski, Jan 23, 2010
  21. 05/10 gitweb: Use Cache::Cache compatibile (get, set) output caching (WIP)Jakub Narebski, Jan 23, 2010
  22. 06/10 gitweb/cache.pm - Adaptive cache expiration time (WIP)Jakub Narebski, Jan 23, 2010
  23. 07/10 gitweb: Use CHI compatibile (compute method) caching (WIP)Jakub Narebski, Jan 23, 2010
  24. 08/10 gitweb/cache.pm - Use locking to avoid 'stampeding herd' problem (WIP)Jakub Narebski, Jan 23, 2010
  25. 09/10 gitweb/cache.pm - Serve stale data when waiting for filling cache (WIP)Jakub Narebski, Jan 23, 2010
  26. 10/10 gitweb: Show appropriate "Generating..." page when regenerating cache (WIP)Jakub Narebski, Jan 23, 2010
  27. Petr BaudisJan 24, 2010
  28. Jakub NarebskiJan 25, 2010
  29. Jakub NarebskiJan 25, 2010
  30. Jakub NarebskiJan 25, 2010
  31. Petr BaudisJan 25, 2010
  32. Jakub NarebskiJan 25, 2010
  33. Petr BaudisJan 25, 2010
  34. J.H.Jan 25, 2010
  35. Jakub NarebskiJan 26, 2010
  36. Petr BaudisJan 28, 2010
  37. Jakub NarebskiJan 31, 2010
  38. Jakub NarebskiJan 25, 2010
  39. J.H.Jan 25, 2010
  40. Jakub NarebskiJan 26, 2010
  41. Jakub NarebskiJan 16, 2010
  42. Junio C HamanoJan 16, 2010
  43. Jakub NarebskiJan 16, 2010
  44. Junio C HamanoJan 16, 2010
  45. Petr BaudisJan 24, 2010
  46. Jakub NarebskiJan 25, 2010
  47. J.H.Jan 25, 2010
  48. Jakub NarebskiJan 25, 2010
  49. Jakub NarebskiJan 15, 2010
  50. Jakub NarebskiJan 23, 2010
  51. Jakub NarebskiJan 15, 2010
  52. Petr BaudisJan 24, 2010
  53. Jakub NarebskiJan 24, 2010
  54. Jakub NarebskiJan 15, 2010
  55. Jakub NarebskiJan 15, 2010
  56. Jakub NarebskiJan 15, 2010
  57. J.H.Jan 15, 2010
  58. Jakub NarebskiJan 15, 2010
  59. Jakub NarebskiJan 23, 2010
  60. Jakub NarebskiFeb 7, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.