]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/AltId.pm
support altid mechanism for v2
[public-inbox.git] / lib / PublicInbox / AltId.pm
index d1b2dc24229cc2f2ab5761f982d47193527a5040..f8aa4cb8cf71a244d369fc671bf3639d635acdb4 100644 (file)
@@ -22,17 +22,31 @@ sub new {
        } split(/[&;]/, $query);
        my $f = $params{file} or die "file: required for $type spec $spec\n";
        unless (index($f, '/') == 0) {
-               $f = "$inbox->{mainrepo}/public-inbox/$f";
+               if (($inbox->{version} || 1) == 1) {
+                       $f = "$inbox->{mainrepo}/public-inbox/$f";
+               } else {
+                       $f = "$inbox->{mainrepo}/$f";
+               }
        }
        bless {
-               mm_alt => PublicInbox::Msgmap->new_file($f, $writable),
+               filename => $f,
+               writable => $writable,
                xprefix => 'X'.uc($prefix),
        }, $class;
 }
 
+sub mm_alt {
+       my ($self) = @_;
+       $self->{mm_alt} ||= eval {
+               my $f = $self->{filename};
+               my $writable = $self->{filename};
+               PublicInbox::Msgmap->new_file($f, $writable);
+       };
+}
+
 sub mid2alt {
        my ($self, $mid) = @_;
-       $self->{mm_alt}->num_for($mid);
+       $self->mm_alt->num_for($mid);
 }
 
 1;