]> Sergey Matveev's repositories - public-inbox.git/commitdiff
extmsg: rework partial MID matching to favor current inbox
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Mon, 19 Mar 2018 07:51:09 +0000 (07:51 +0000)
committerEric Wong <e@80x24.org>
Mon, 19 Mar 2018 07:51:59 +0000 (07:51 +0000)
The current inbox is more important for partial Message-ID
matching, so we try harder on that to fix common errors before
moving onto other inboxes.  Then, prevent expensive scanning of
other inboxes by requiring a Message-ID length of at least 16
bytes.

Finally, we limit the overall partial responses to 200 when
scanning other inboxes to avoid excessive memory usage.

lib/PublicInbox/ExtMsg.pm

index ab9591f9fc195810a5cea30de84e1ed2d8e8bd24..e0aabfb1ab4cca2ed61ab40c167be4a2d35b1f06 100644 (file)
@@ -84,17 +84,33 @@ sub ext_msg {
        my $n_partial = 0;
        my @partial;
 
-       eval { require PublicInbox::Msgmap };
-       my $have_mm = $@ ? 0 : 1;
-       if ($have_mm) {
+       if (my $mm = $cur->mm) {
+               my $tmp_mid = $mid;
+               my $res = $mm->mid_prefixes($tmp_mid, 100);
+               if ($res && scalar(@$res)) {
+                       $n_partial += scalar(@$res);
+                       push @partial, [ $cur, $res ];
+               # fixup common errors:
+               } elsif ($tmp_mid =~ s,/[tTf],,) {
+                       $res = $mm->mid_prefixes($tmp_mid, 100);
+                       if ($res && scalar(@$res)) {
+                               $n_partial += scalar(@$res);
+                               push @partial, [ $cur, $res ];
+                       }
+               }
+       }
+
+       # can't find a partial match in current inbox, try the others:
+       if (!$n_partial && length($mid) >= 16) {
                my $tmp_mid = $mid;
 again:
-               unshift @ibx, $cur;
                foreach my $ibx (@ibx) {
                        my $mm = $ibx->mm or next;
-                       if (my $res = $mm->mid_prefixes($tmp_mid)) {
+                       my $res = $mm->mid_prefixes($tmp_mid, 100);
+                       if ($res && scalar(@$res)) {
                                $n_partial += scalar(@$res);
                                push @partial, [ $ibx, $res ];
+                               last if $n_partial >= 100;
                        }
                }
                # fixup common errors: