From: Eric Wong Date: Fri, 24 Jul 2020 05:55:55 +0000 (+0000) Subject: search: avoid copying {inboxdir} X-Git-Tag: v1.6.0~216 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=298c806d51f31796caa65da70ab6bfa310db614a;p=public-inbox.git search: avoid copying {inboxdir} Instead, storing {xdir} will allow us to avoid string concatenation in the read-only path and save us a little hash entry space. --- diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index 55eee41c..4e08aed7 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -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; diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 4b1b1736..2d53b2d0 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -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); }; }