From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id CE9881F8EF for ; Fri, 24 Jul 2020 05:56:08 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 09/20] search: avoid copying {inboxdir} Date: Fri, 24 Jul 2020 05:55:55 +0000 Message-Id: <20200724055606.27332-10-e@yhbt.net> In-Reply-To: <20200724055606.27332-1-e@yhbt.net> References: <20200724055606.27332-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 25 +++++++++++++++---------- lib/PublicInbox/SearchIdx.pm | 5 +++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index 55eee41ca..4e08aed7a 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 4b1b1736e..2d53b2d03 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); }; }