Implement cache of front page.
authormwolson_admin <mwolson_admin@deleuze.hcoop.net>
Sun, 22 Jun 2008 04:59:58 +0000 (00:59 -0400)
committermwolson_admin <mwolson_admin@deleuze.hcoop.net>
Sun, 22 Jun 2008 04:59:58 +0000 (00:59 -0400)
gitweb.cgi

index ab8481b..5d244a7 100755 (executable)
@@ -58,6 +58,8 @@ our $site_header = "";
 our $home_text = "indextext.html";
 # filename of html text to include at bottom of each page
 our $site_footer = "";
 our $home_text = "indextext.html";
 # filename of html text to include at bottom of each page
 our $site_footer = "";
+# filename of cached version of front page
+our $cached_front_page = "/var/local/lib/gitweb/indexcache.html";
 
 # URI of stylesheets
 our @stylesheets = ("gitweb.css");
 
 # URI of stylesheets
 our @stylesheets = ("gitweb.css");
@@ -422,6 +424,39 @@ if (defined $file_parent) {
        }
 }
 
        }
 }
 
+sub git_send_cached_front_page {
+       my $status = shift || "200 OK";
+       my $expires = shift;
+       my $content_type;
+       # require explicit support from the UA if we are to send the page as
+       # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
+       # we have to do this because MSIE sometimes globs '*/*', pretending to
+       # support xhtml+xml but choking when it gets what it asked for.
+       if (defined $cgi->http('HTTP_ACCEPT') &&
+           $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ &&
+           $cgi->Accept('application/xhtml+xml') != 0) {
+               $content_type = 'application/xhtml+xml';
+       } else {
+               $content_type = 'text/html';
+       }
+       print $cgi->header(-type=>$content_type, -charset => 'utf-8',
+                          -status=> $status, -expires => $expires);
+       open (my $fd, $cached_front_page);
+       print <$fd>;
+       close $fd;
+       exit;
+}
+
+# Display a cached page if no parameters were provided and the
+# "nocache" parameter was not passed.
+our $nocache = $cgi->param('nocache');
+our @params = $cgi->Vars;
+use Data::Dumper;
+if ($cached_front_page && ! defined $nocache && scalar @params == 0
+    && -f $cached_front_page && -r $cached_front_page) {
+       git_send_cached_front_page();
+}
+
 # parameters which are refnames
 our $hash = $cgi->param('h');
 if (defined $hash) {
 # parameters which are refnames
 our $hash = $cgi->param('h');
 if (defined $hash) {