]> Sergey Matveev's repositories - public-inbox.git/commitdiff
inbox: altid_map becomes a method
authorEric Wong <e@yhbt.net>
Thu, 26 Mar 2020 08:21:27 +0000 (08:21 +0000)
committerEric Wong <e@yhbt.net>
Thu, 26 Mar 2020 23:47:07 +0000 (23:47 +0000)
We want to be able to preload that, as well as to access it
in WwwText for a config comment in the config example.

lib/PublicInbox/Inbox.pm
lib/PublicInbox/WWW.pm
lib/PublicInbox/WwwAltId.pm

index 4f27d1bbb65f9aa5dee21b66aa5eb8202004f796..95ffd039fdb7390b359c66bd30be6080d280e7cc 100644 (file)
@@ -376,4 +376,19 @@ sub modified {
        git($self)->modified; # v1
 }
 
+# returns prefix => pathname mapping
+# (pathname is NOT public, but prefix is used for Xapian queries)
+sub altid_map ($) {
+       my ($self) = @_;
+       $self->{-altid_map} //= eval {
+               require PublicInbox::AltId;
+               my $altid = $self->{altid} or return {};
+               my %h = map {;
+                       my $x = PublicInbox::AltId->new($self, $_);
+                       "$x->{prefix}" => $x->{filename}
+               } @$altid;
+               \%h;
+       } // {};
+}
+
 1;
index 5017f572c8947978e252463afe6df511ee4b9137..56d2c42a41cd8eafd37444e68495644f28a80388 100644 (file)
@@ -170,6 +170,7 @@ sub preload {
 
 sub preload_inbox {
        my $ibx = shift;
+       $ibx->altid_map;
        $ibx->cloneurl;
        $ibx->description;
        $ibx->base_url;
index 34641a926c0c4393ac08562f437c07b89d04cff6..a45d8061069e9402d8ab72c9d3af1f09895aa356 100644 (file)
@@ -10,18 +10,6 @@ use PublicInbox::AltId;
 use PublicInbox::Spawn qw(which);
 our $sqlite3 = $ENV{SQLITE3};
 
-# returns prefix => pathname mapping
-# (pathname is NOT public, but prefix is used for Xapian queries)
-sub altid_map ($) {
-       my ($ibx) = @_;
-       my $altid = $ibx->{altid} or return {};
-       my %h = map {;
-               my $x = PublicInbox::AltId->new($ibx, $_);
-               "$x->{prefix}" => $x->{filename}
-       } @$altid;
-       \%h;
-}
-
 sub sqlite3_missing ($) {
        PublicInbox::WwwResponse::oneshot($_[0], 501, \<<EOF);
 <pre>sqlite3 not available
@@ -51,7 +39,7 @@ sub check_output {
 sub sqldump ($$) {
        my ($ctx, $altid_pfx) = @_;
        my $ibx = $ctx->{-inbox};
-       my $altid_map = $ibx->{-altid_map} //= altid_map($ibx);
+       my $altid_map = $ibx->altid_map;
        my $fn = $altid_map->{$altid_pfx};
        unless (defined $fn) {
                return PublicInbox::WwwStream::oneshot($ctx, 404, \<<EOF);