]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
repo: lazily read description and cloneurl
authorEric Wong <e@80x24.org>
Sat, 11 Feb 2017 00:41:29 +0000 (00:41 +0000)
committerEric Wong <e@80x24.org>
Sat, 11 Feb 2017 01:08:08 +0000 (01:08 +0000)
This improves startup speed at the cost of CoW-friendliness
for long-lived daemons (which can be fixed, later).

lib/PublicInbox/Repo.pm
lib/PublicInbox/RepoBase.pm
lib/PublicInbox/RepoConfig.pm
lib/PublicInbox/RepoGitAtom.pm
lib/PublicInbox/RepoRoot.pm

index 812b1071c901c40ca1ee508a9f4e2424cd4a919e..e53d6975dcd6df658913c6657c65ca4b83e2e00f 100644 (file)
@@ -6,10 +6,42 @@
 package PublicInbox::Repo;
 use strict;
 use warnings;
+use PublicInbox::Config;
 
 sub new {
        my ($class, $opts) = @_;
        bless $opts, $class;
 }
 
+sub description {
+       my ($self) = @_;
+       my $desc = $self->{description};
+       return $desc if defined $desc;
+       $desc = PublicInbox::Config::try_cat("$self->{path}/description");
+       local $/ = "\n";
+       chomp $desc;
+       $desc =~ s/\s+/ /smg;
+       $desc = '($GIT_DIR/description missing)' if $desc eq '';
+       $self->{description} = $desc;
+}
+
+sub desc_html {
+       my ($self) = @_;
+       $self->{desc_html} ||=
+               PublicInbox::Hval->utf8($self->description)->as_html;
+}
+
+sub cloneurl {
+       my ($self) = @_;
+       my $url = $self->{cloneurl};
+       return $url if $url;
+       if ($self->{vcs} eq 'git') {
+               $url = PublicInbox::Config::try_cat("$self->{path}/cloneurl");
+               $url = [ split(/\s+/s, $url) ];
+               local $/ = "\n";
+               chomp @$url;
+       }
+       $self->{cloneurl} = $url;
+}
+
 1;
index e60677d65dc2381f2ee4ea261a123158c5d56a20..97f13b2568c84a776f2ff4222ca6a2a4ebdcee16 100644 (file)
@@ -59,7 +59,7 @@ sub mime_type {
 # starts an HTML page for Repobrowse in a consistent way
 sub html_start {
        my ($self, $req, $title_html, $opts) = @_;
-       my $desc = $req->{repo_info}->{desc_html};
+       my $desc = $req->{repo_info}->desc_html;
        my $meta = '';
 
        if ($opts) {
index fb1fd584cbeef7a420e9d666047a98f0f71dcf51..e1e2860bc6cde1b0944ffb72b27e5933cc07514b 100644 (file)
@@ -30,8 +30,6 @@ sub default_file {
 # Returns something like:
 # {
 #      path => '/home/git/foo.git',
-#      description => 'foo repo',
-#      cloneurl => "git://example.com/foo.git\nhttp://example.com/foo.git",
 #      publicinbox => '/home/pub/foo-public.git',
 # }
 sub lookup {
@@ -51,14 +49,6 @@ sub lookup {
        $rv->{snapshot_re} = qr/\A\Q$snap\E[-_]/;
        $rv->{snapshot_pfx} = $snap;
 
-       # gitweb compatibility
-       foreach my $key (qw(description cloneurl)) {
-               $rv->{$key} = PublicInbox::Config::try_cat("$path/$key");
-       }
-
-       $rv->{desc_html} =
-               PublicInbox::Hval->new_oneline($rv->{description})->as_html;
-
        foreach my $key (qw(publicinbox vcs readme group snapshots)) {
                $rv->{$key} = $self->{"repo.$repo_path.$key"};
        }
index a9f40126160823d299d163a605e99efe27a1180f..6d0caa02b7da23dc505a01ea93ab4abd6d8f03ab 100644 (file)
@@ -70,10 +70,11 @@ sub git_atom_sed ($$) {
        $title = utf8_html("$title, branch $req->{q}->{h}");
        my $url = repo_root_url($self, $req);
        my $hdr = {};
+       my $subtitle = $repo_info->desc_html;
        $req->{axml} = qq(<?xml version="1.0"?>\n) .
                qq(<feed\nxmlns="http://www.w3.org/2005/Atom">) .
                qq(<title>$title</title>) .
-               qq(<subtitle>$repo_info->{desc_html}</subtitle>) .
+               qq(<subtitle>$subtitle</subtitle>) .
                qq(<link\nrel="alternate"\ntype="text/html"\nhref="$url"\n/>);
        my ($plinks, $id, $ai);
        my $end = '';
index 9ab25b977621ea1275d12860090181d8c726dd2a..c04c23c554a87e38fcb8df0532fb96af84240406 100644 (file)
@@ -46,7 +46,7 @@ sub repobrowse_index {
                my $l = $p->as_html;
                $p = $p->as_path;
                $fh->write(qq(<tr><td><tt><a\nhref="$p">$l</a></tt></td>) .
-                       "<td><tt> $r->{desc_html}</tt></td></tr>");
+                       '<td><tt> '.$r->desc_html.'</tt></td></tr>');
        }
 
        foreach my $group (keys %$groups) {
@@ -61,7 +61,7 @@ sub repobrowse_index {
                        $p = $p->as_path;
                        $fh->write('<tr><td><tt> ' .
                                qq(<a\nhref="$p">$l</a></tt></td>) .
-                               "<td><tt> $r->{desc_html}</tt></td></tr>");
+                               '<td><tt> '.$r->desc_html.'</tt></td></tr>');
                }
        }