about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-29 09:57:56 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-29 10:00:08 +0000
commit34d6aff1ca223521d8137f642a58db077ab70df0 (patch)
tree04ce63866f65b593dd6029b9f6a80dccd0f252c1 /lib
parenta11bcd26245427e16f7e62d99b9707522e2d64e2 (diff)
downloadpublic-inbox-34d6aff1ca223521d8137f642a58db077ab70df0.tar.gz
Back in the day, we compressed long Message-IDs to SHA-1
hexdigests for the URL.  This now redirects to a 301 in
the hopes we can remove these checks some day to reduce
overhead.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/Inbox.pm11
-rw-r--r--lib/PublicInbox/WWW.pm23
2 files changed, 17 insertions, 17 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 01aa500c..265360d9 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -293,13 +293,18 @@ sub path_check {
         git($self)->check('HEAD:'.$path);
 }
 
+sub mid2num($$) {
+        my ($self, $mid) = @_;
+        my $mm = mm($self) or return;
+        $mm->num_for($mid);
+}
+
 sub smsg_by_mid ($$) {
         my ($self, $mid) = @_;
         my $srch = search($self) or return;
         # favor the Message-ID we used for the NNTP article number:
-        my $mm = mm($self) or return;
-        my $num = $mm->num_for($mid);
-        $srch->lookup_article($num);
+        my $num = mid2num($self, $mid);
+        defined $num ? $srch->lookup_article($num) : undef;
 }
 
 sub msg_by_mid ($$;$) {
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 7bd29732..24e24f1e 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -169,14 +169,15 @@ sub invalid_inbox_mid {
         return $ret if $ret;
 
         $ctx->{mid} = $mid;
-        if ($mid =~ /\A[a-f0-9]{40}\z/) {
-                # this is horiffically wasteful for legacy URLs:
-                if ($mid = mid2blob($ctx)) {
-                        require Email::Simple;
-                        use PublicInbox::MID qw/mid_clean/;
-                        my $s = Email::Simple->new($mid);
-                        $ctx->{mid} = mid_clean($s->header('Message-ID'));
-                }
+        my $ibx = $ctx->{-inbox};
+        if ($mid =~ m!\A([a-f0-9]{2})([a-f0-9]{38})\z!) {
+                my ($x2, $x38) = ($1, $2);
+                # this is horrifically wasteful for legacy URLs:
+                my $str = $ctx->{-inbox}->msg_by_path("$x2/$x38") or return;
+                require Email::Simple;
+                my $s = Email::Simple->new($str);
+                $mid = PublicInbox::MID::mid_clean($s->header('Message-ID'));
+                return r301($ctx, $inbox, $mid);
         }
         undef;
 }
@@ -208,12 +209,6 @@ sub get_index {
         }
 }
 
-# just returns a string ref for the blob in the current ctx
-sub mid2blob {
-        my ($ctx) = @_;
-        $ctx->{-inbox}->msg_by_mid($ctx->{mid});
-}
-
 # /$INBOX/$MESSAGE_ID/raw                    -> raw mbox
 sub get_mid_txt {
         my ($ctx) = @_;