]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/NewsWWW.pm
isearch: emulate per-inbox search with ->ALL
[public-inbox.git] / lib / PublicInbox / NewsWWW.pm
index be1d43efa6312b549d701188184cedae5cc47160..ade8dfd175f402af2bebcaf7fb446f850a783e30 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Plack app redirector for mapping /$NEWSGROUP requests to
@@ -63,7 +63,6 @@ sub call {
                return redirect($code, $url);
        }
 
-       my $res;
        my @try = (join('/', @parts));
 
        # trailing slash is in the rest of our WWW, so maybe some users
@@ -72,13 +71,30 @@ sub call {
                pop @parts;
                push @try, join('/', @parts);
        }
-
-       foreach my $mid (@try) {
-               my $arg = [ $mid ];
-               $pi_config->each_inbox(\&try_inbox, $arg);
-               defined($res = $arg->[1]) and last;
+       my $ALL = $pi_config->ALL;
+       if (my $over = $ALL ? $ALL->over : undef) {
+               my $by_eidx_key = $pi_config->{-by_eidx_key};
+               for my $mid (@try) {
+                       my ($id, $prev);
+                       while (my $x = $over->next_by_mid($mid, \$id, \$prev)) {
+                               my $xr3 = $over->get_xref3($x->{num});
+                               for (@$xr3) {
+                                       s/:[0-9]+:$x->{blob}\z// or next;
+                                       my $ibx = $by_eidx_key->{$_} // next;
+                                       my $url = $ibx->base_url or next;
+                                       $url .= mid_escape($mid) . '/';
+                                       return redirect(302, $url);
+                               }
+                       }
+               }
+       } else { # slow path, scan every inbox
+               for my $mid (@try) {
+                       my $arg = [ $mid ]; # [1] => result
+                       $pi_config->each_inbox(\&try_inbox, $arg);
+                       return $arg->[1] if $arg->[1];
+               }
        }
-       $res || [ 404, [qw(Content-Type text/plain)], ["404 Not Found\n"] ];
+       [ 404, [qw(Content-Type text/plain)], ["404 Not Found\n"] ];
 }
 
 1;