about summary refs log tree commit homepage
path: root/lib/PublicInbox/ManifestJsGz.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-11-23 07:06:01 +0000
committerEric Wong <e@80x24.org>2020-11-24 05:03:55 +0000
commitbe688d5b00bb77c6601b3ab680403ecd71ac4871 (patch)
treecc77f8b9a7dd6f5a357ba47e0b913302547b7be6 /lib/PublicInbox/ManifestJsGz.pm
parent616a08457175b442d4caeb67f9ccd9d3e69f50f5 (diff)
downloadpublic-inbox-be688d5b00bb77c6601b3ab680403ecd71ac4871.tar.gz
For a mirror of lore.kernel.org with >140 inboxes, this speeds
up manifest.js.gz generation from ~1s to 40ms on my HW.  This
is still unacceptable when dealing with thousands of inboxes,
but gets us closer to where we need to be.
Diffstat (limited to 'lib/PublicInbox/ManifestJsGz.pm')
-rw-r--r--lib/PublicInbox/ManifestJsGz.pm39
1 files changed, 32 insertions, 7 deletions
diff --git a/lib/PublicInbox/ManifestJsGz.pm b/lib/PublicInbox/ManifestJsGz.pm
index 3b436827..2c4a231d 100644
--- a/lib/PublicInbox/ManifestJsGz.pm
+++ b/lib/PublicInbox/ManifestJsGz.pm
@@ -21,6 +21,14 @@ sub url_regexp {
         $ctx->SUPER::url_regexp('publicInbox.grokManifest', 'match=domain');
 }
 
+sub inject_entry ($$$;$) {
+        my ($ctx, $url_path, $ent, $git_dir) = @_;
+        $ctx->{-abs2urlpath}->{$git_dir // delete $ent->{git_dir}} = $url_path;
+        my $modified = $ent->{modified};
+        $ctx->{-mtime} = $modified if $modified > ($ctx->{-mtime} // 0);
+        $ctx->{manifest}->{$url_path} = $ent;
+}
+
 sub manifest_add ($$;$$) {
         my ($ctx, $ibx, $epoch, $default_desc) = @_;
         my $url_path = "/$ibx->{name}";
@@ -32,15 +40,10 @@ sub manifest_add ($$;$$) {
                 $git = $ibx->git;
         }
         my $ent = $git->manifest_entry($epoch, $default_desc) or return;
-        $ctx->{-abs2urlpath}->{$git->{git_dir}} = $url_path;
-        my $modified = $ent->{modified};
-        if ($modified > ($ctx->{-mtime} // 0)) {
-                $ctx->{-mtime} = $modified;
-        }
-        $ctx->{manifest}->{$url_path} = $ent;
+        inject_entry($ctx, $url_path, $ent, $git->{git_dir});
 }
 
-sub ibx_entry {
+sub slow_manifest_add ($$) {
         my ($ctx, $ibx) = @_;
         eval {
                 if (defined(my $max = $ibx->max_git_epoch)) {
@@ -52,6 +55,28 @@ sub ibx_entry {
                         manifest_add($ctx, $ibx);
                 }
         };
+}
+
+sub eidx_manifest_add ($$$) {
+        my ($ctx, $ALL, $ibx) = @_;
+        if (my $data = $ALL->misc->inbox_data($ibx)) {
+                $data = $json->decode($data);
+                while (my ($url_path, $ent) = each %$data) {
+                        inject_entry($ctx, $url_path, $ent);
+                }
+        } else {
+                warn "E: `${\$ibx->eidx_key}' not indexed by $ALL->{topdir}\n";
+        }
+}
+
+sub ibx_entry {
+        my ($ctx, $ibx) = @_;
+        my $ALL = $ctx->{www}->{pi_config}->ALL;
+        if ($ALL) {
+                eidx_manifest_add($ctx, $ALL, $ibx);
+        } else {
+                slow_manifest_add($ctx, $ibx);
+        }
         warn "E: $@" if $@;
 }