unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/2] manifest.js.gz: avoid long-lived per-epoch cat-file processes
Date: Sat, 11 Sep 2021 23:30:45 +0000	[thread overview]
Message-ID: <20210911233046.23862-2-e@80x24.org> (raw)
In-Reply-To: <20210911233046.23862-1-e@80x24.org>

When generating per-inbox manifests, we were forgetting to
cleanup per-epoch "git cat-file --batch" processes.  Our
previous method of generating modified times was also stupidly
inefficient, so replace the pipeline with a single
"git for-each-ref" invocation.
---
 lib/PublicInbox/Git.pm          | 25 +++++--------------------
 lib/PublicInbox/ManifestJsGz.pm |  2 +-
 2 files changed, 6 insertions(+), 21 deletions(-)

diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index e557f6d6..219a1732 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -16,7 +16,7 @@ use Errno qw(EINTR EAGAIN);
 use File::Glob qw(bsd_glob GLOB_NOSORT);
 use File::Spec ();
 use Time::HiRes qw(stat);
-use PublicInbox::Spawn qw(popen_rd);
+use PublicInbox::Spawn qw(popen_rd spawn);
 use PublicInbox::Tmpfile;
 use IO::Poll qw(POLLIN);
 use Carp qw(croak);
@@ -466,28 +466,13 @@ sub cat_async ($$$;$) {
 	push(@$inflight, $oid, $cb, $arg);
 }
 
-sub extract_cmt_time {
-	my ($bref, undef, undef, undef, $modified) = @_;
-
-	if ($$bref =~ /^committer .*?> ([0-9]+) [\+\-]?[0-9]+/sm) {
-		my $cmt_time = $1 + 0;
-		$$modified = $cmt_time if $cmt_time > $$modified;
-	}
-}
-
 # returns the modified time of a git repo, same as the "modified" field
 # of a grokmirror manifest
 sub modified ($) {
-	my ($self) = @_;
-	my $modified = 0;
-	my $fh = popen($self, qw(rev-parse --branches));
-	local $/ = "\n";
-	while (my $oid = <$fh>) {
-		chomp $oid;
-		cat_async($self, $oid, \&extract_cmt_time, \$modified);
-	}
-	cat_async_wait($self);
-	$modified || time;
+	# committerdate:unix is git 2.9.4+ (2017-05-05), so using raw instead
+	my $fh = popen($_[0], qw[for-each-ref --sort=-committerdate
+				--format=%(committerdate:raw) --count=1]);
+	(split(/ /, <$fh> // time))[0] + 0; # integerize for JSON
 }
 
 # for grokmirror, which doesn't read gitweb.description
diff --git a/lib/PublicInbox/ManifestJsGz.pm b/lib/PublicInbox/ManifestJsGz.pm
index 69d81fa1..cde60245 100644
--- a/lib/PublicInbox/ManifestJsGz.pm
+++ b/lib/PublicInbox/ManifestJsGz.pm
@@ -27,7 +27,7 @@ sub inject_entry ($$$;$) {
 	$ctx->{manifest}->{$url_path} = $ent;
 }
 
-sub manifest_add ($$;$$) { # slow path w/o extindex "all"
+sub manifest_add ($$;$$) { # slow path w/o extindex "all" (or per-inbox)
 	my ($ctx, $ibx, $epoch, $default_desc) = @_;
 	my $url_path = "/$ibx->{name}";
 	my $git;

  reply	other threads:[~2021-09-11 23:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11 23:30 [PATCH 0/2] www: per-inbox manifest.js.gz improvements Eric Wong
2021-09-11 23:30 ` Eric Wong [this message]
2021-09-11 23:30 ` [PATCH 2/2] www: use ->ALL for per-inbox manifest.js.gz, too Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210911233046.23862-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).