]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ManifestJsGz.pm
update copyrights for 2021
[public-inbox.git] / lib / PublicInbox / ManifestJsGz.pm
index 3d8a38ae3ca969622e21aea7589f34102208b00a..31cf15dcfe0b6b8df64ba0b8a479afe7d98542b2 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 all contributors <meta@public-inbox.org>
+# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # generates manifest.js.gz for grokmirror(1)
@@ -7,13 +7,11 @@ use strict;
 use v5.10.1;
 use parent qw(PublicInbox::WwwListing);
 use bytes (); # length
-use PublicInbox::Inbox;
 use PublicInbox::Config;
-use PublicInbox::Git;
 use IO::Compress::Gzip qw(gzip);
 use HTTP::Date qw(time2str);
 
-our $json = PublicInbox::Config::json();
+my $json = PublicInbox::Config::json();
 
 # called by WwwListing
 sub url_regexp {
@@ -23,26 +21,29 @@ 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}";
-       my $git_dir = $ibx->{inboxdir};
+       my $git;
        if (defined $epoch) {
-               $git_dir .= "/git/$epoch.git";
                $url_path .= "/git/$epoch.git";
+               $git = $ibx->git_epoch($epoch) or return;
+       } else {
+               $git = $ibx->git;
        }
-       return unless -d $git_dir;
-       my $git = PublicInbox::Git->new($git_dir);
        my $ent = $git->manifest_entry($epoch, $default_desc) or return;
-       $ctx->{-abs2urlpath}->{$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)) {
@@ -54,6 +55,29 @@ 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);
+               delete $data->{''}; # private
+               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_cfg}->ALL;
+       if ($ALL) {
+               eidx_manifest_add($ctx, $ALL, $ibx);
+       } else {
+               slow_manifest_add($ctx, $ibx);
+       }
        warn "E: $@" if $@;
 }
 
@@ -75,4 +99,11 @@ sub psgi_triple {
                 'Content-Length', bytes::length($out) ], [ $out ] ]
 }
 
+sub per_inbox {
+       my ($ctx) = @_;
+       # only one inbox, slow is probably OK
+       slow_manifest_add($ctx, $ctx->{ibx});
+       psgi_triple($ctx);
+}
+
 1;