]> Sergey Matveev's repositories - public-inbox.git/commitdiff
search: avoid copying {inboxdir}
authorEric Wong <e@yhbt.net>
Fri, 24 Jul 2020 05:55:55 +0000 (05:55 +0000)
committerEric Wong <e@yhbt.net>
Sat, 25 Jul 2020 20:48:18 +0000 (20:48 +0000)
Instead, storing {xdir} will allow us to avoid string
concatenation in the read-only path and save us a little
hash entry space.

lib/PublicInbox/Search.pm
lib/PublicInbox/SearchIdx.pm

index 55eee41ca4a88c43594e9e0899c3dba25e77771e..4e08aed7acbf0697ccdd9593325080b63e8e637d 100644 (file)
@@ -164,15 +164,10 @@ chomp @HELP;
 
 sub xdir ($;$) {
        my ($self, $rdonly) = @_;
-       if ($self->{ibx_ver} == 1) {
-               "$self->{inboxdir}/public-inbox/xapian" . SCHEMA_VERSION;
-       } else {
-               my $dir = "$self->{inboxdir}/xap" . SCHEMA_VERSION;
-               return $dir if $rdonly;
-
-               my $shard = $self->{shard};
-               defined $shard or die "shard not given";
-               $dir .= "/$shard";
+       if ($rdonly || !defined($self->{shard})) {
+               $self->{xpfx};
+       } else { # v2 only:
+               "$self->{xpfx}/$self->{shard}";
        }
 }
 
@@ -220,14 +215,24 @@ sub xdb ($) {
        };
 }
 
+sub xpfx_init ($) {
+       my ($self) = @_;
+       if ($self->{ibx_ver} == 1) {
+               $self->{xpfx} .= '/public-inbox/xapian' . SCHEMA_VERSION;
+       } else {
+               $self->{xpfx} .= '/xap'.SCHEMA_VERSION;
+       }
+}
+
 sub new {
        my ($class, $ibx) = @_;
        ref $ibx or die "BUG: expected PublicInbox::Inbox object: $ibx";
        my $self = bless {
-               inboxdir => $ibx->{inboxdir},
+               xpfx => $ibx->{inboxdir}, # for xpfx_init
                altid => $ibx->{altid},
                ibx_ver => $ibx->version,
        }, $class;
+       xpfx_init($self);
        my $dir = xdir($self, 1);
        $self->{over_ro} = PublicInbox::Over->new("$dir/over.sqlite3");
        $self;
index 4b1b1736e2270b3ccdec5ae1c2b79ef9db7b0043..2d53b2d034de2d5d02a11a990e63f62820ccf6a6 100644 (file)
@@ -49,12 +49,13 @@ sub new {
        }
        $ibx = PublicInbox::InboxWritable->new($ibx);
        my $self = bless {
-               inboxdir => $inboxdir,
                ibx => $ibx,
+               xpfx => $inboxdir, # for xpfx_init
                -altid => $altid,
                ibx_ver => $version,
                indexlevel => $indexlevel,
        }, $class;
+       $self->xpfx_init;
        $self->{-set_indexlevel_once} = 1 if $indexlevel eq 'medium';
        $ibx->umask_prepare;
        if ($version == 1) {
@@ -371,7 +372,7 @@ sub _msgmap_init ($) {
        die "BUG: _msgmap_init is only for v1\n" if $self->{ibx_ver} != 1;
        $self->{mm} //= eval {
                require PublicInbox::Msgmap;
-               PublicInbox::Msgmap->new($self->{inboxdir}, 1);
+               PublicInbox::Msgmap->new($self->{ibx}->{inboxdir}, 1);
        };
 }