]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WWW.pm
www: cleanup expensive fallback for legacy URLs
[public-inbox.git] / lib / PublicInbox / WWW.pm
index 7bd29732ddd3d54e165b2910c27e25ef14fab087..24e24f1ee810554fbefc033f36d5da2bd5365193 100644 (file)
@@ -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) = @_;