From 60f38818f2dbc76e20041cf1b01e2baf3322a1f1 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 11 Feb 2017 00:41:29 +0000 Subject: repo: lazily read description and cloneurl This improves startup speed at the cost of CoW-friendliness for long-lived daemons (which can be fixed, later). --- lib/PublicInbox/Repo.pm | 32 ++++++++++++++++++++++++++++++++ lib/PublicInbox/RepoBase.pm | 2 +- lib/PublicInbox/RepoConfig.pm | 10 ---------- lib/PublicInbox/RepoGitAtom.pm | 3 ++- lib/PublicInbox/RepoRoot.pm | 4 ++-- 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/lib/PublicInbox/Repo.pm b/lib/PublicInbox/Repo.pm index 812b1071..e53d6975 100644 --- a/lib/PublicInbox/Repo.pm +++ b/lib/PublicInbox/Repo.pm @@ -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; diff --git a/lib/PublicInbox/RepoBase.pm b/lib/PublicInbox/RepoBase.pm index e60677d6..97f13b25 100644 --- a/lib/PublicInbox/RepoBase.pm +++ b/lib/PublicInbox/RepoBase.pm @@ -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) { diff --git a/lib/PublicInbox/RepoConfig.pm b/lib/PublicInbox/RepoConfig.pm index fb1fd584..e1e2860b 100644 --- a/lib/PublicInbox/RepoConfig.pm +++ b/lib/PublicInbox/RepoConfig.pm @@ -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"}; } diff --git a/lib/PublicInbox/RepoGitAtom.pm b/lib/PublicInbox/RepoGitAtom.pm index a9f40126..6d0caa02 100644 --- a/lib/PublicInbox/RepoGitAtom.pm +++ b/lib/PublicInbox/RepoGitAtom.pm @@ -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(\n) . qq() . qq($title) . - qq($repo_info->{desc_html}) . + qq($subtitle) . qq(); my ($plinks, $id, $ai); my $end = ''; diff --git a/lib/PublicInbox/RepoRoot.pm b/lib/PublicInbox/RepoRoot.pm index 9ab25b97..c04c23c5 100644 --- a/lib/PublicInbox/RepoRoot.pm +++ b/lib/PublicInbox/RepoRoot.pm @@ -46,7 +46,7 @@ sub repobrowse_index { my $l = $p->as_html; $p = $p->as_path; $fh->write(qq($l) . - " $r->{desc_html}"); + ' '.$r->desc_html.''); } foreach my $group (keys %$groups) { @@ -61,7 +61,7 @@ sub repobrowse_index { $p = $p->as_path; $fh->write(' ' . qq($l) . - " $r->{desc_html}"); + ' '.$r->desc_html.''); } } -- cgit v1.2.3-24-ge0c7