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-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,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 2EBBB1F8C7 for ; Tue, 17 Aug 2021 08:52:42 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/3] lei: add ->lms shortcut for LeiMailSync Date: Tue, 17 Aug 2021 08:52:39 +0000 Message-Id: <20210817085241.25592-2-e@80x24.org> In-Reply-To: <20210817085241.25592-1-e@80x24.org> References: <20210817085241.25592-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We access this read-only in many places (and will in more), so provide a shortcut to simplify callers. --- lib/PublicInbox/LEI.pm | 9 +++++++++ lib/PublicInbox/LeiBlob.pm | 3 +-- lib/PublicInbox/LeiForgetMailSync.pm | 3 +-- lib/PublicInbox/LeiInspect.pm | 3 +-- lib/PublicInbox/LeiLcat.pm | 10 ++++------ lib/PublicInbox/LeiLsMailSource.pm | 3 +-- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm index 347dd280..e5232f1b 100644 --- a/lib/PublicInbox/LEI.pm +++ b/lib/PublicInbox/LEI.pm @@ -1425,4 +1425,13 @@ sub git_blob_id { ($lei->{sto} // _lei_store($lei, 1))->git_blob_id($eml); } +sub lms { # read-only LeiMailSync + my ($lei) = @_; + my $lse = $lei->{lse} // do { + my $sto = $lei->{sto} // _lei_store($lei); + $sto ? $sto->search : undef + }; + $lse ? $lse->lms : undef; +} + 1; diff --git a/lib/PublicInbox/LeiBlob.pm b/lib/PublicInbox/LeiBlob.pm index 3158ca3b..21003894 100644 --- a/lib/PublicInbox/LeiBlob.pm +++ b/lib/PublicInbox/LeiBlob.pm @@ -133,8 +133,7 @@ sub lei_blob { } my $ce = $?; return if $ce == 0; - my $sto = $lei->_lei_store; - my $lms = $sto ? $sto->search->lms : undef; + my $lms = $lei->lms; if (my $bref = $lms ? $lms->local_blob($blob, 1) : undef) { defined($lei->{-attach_idx}) and return extract_attach($lei, $blob, $bref); diff --git a/lib/PublicInbox/LeiForgetMailSync.pm b/lib/PublicInbox/LeiForgetMailSync.pm index 46dde1a7..c74ba25d 100644 --- a/lib/PublicInbox/LeiForgetMailSync.pm +++ b/lib/PublicInbox/LeiForgetMailSync.pm @@ -14,8 +14,7 @@ use PublicInbox::LeiExportKw; sub lei_forget_mail_sync { my ($lei, @folders) = @_; - my $sto = $lei->_lei_store or return; - my $lms = $sto->search->lms or return; + my $lms = $lei->lms or return; my $err = $lms->arg2folder($lei, \@folders); $lei->qerr(@{$err->{qerr}}) if $err->{qerr}; return $lei->fail($err->{fail}) if $err->{fail}; diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm index bf7a4836..2d2ff1a0 100644 --- a/lib/PublicInbox/LeiInspect.pm +++ b/lib/PublicInbox/LeiInspect.pm @@ -41,8 +41,7 @@ sub inspect_imap_uid ($$) { sub inspect_sync_folder ($$) { my ($lei, $folder) = @_; my $ent = {}; - my $lse = $lei->{lse} or return $ent; - my $lms = $lse->lms or return $ent; + my $lms = $lei->lms or return $ent; my $folders = [ $folder ]; my $err = $lms->arg2folder($lei, $folders); if ($err) { diff --git a/lib/PublicInbox/LeiLcat.pm b/lib/PublicInbox/LeiLcat.pm index 4a0c24a9..9d95e899 100644 --- a/lib/PublicInbox/LeiLcat.pm +++ b/lib/PublicInbox/LeiLcat.pm @@ -13,7 +13,7 @@ use PublicInbox::MID qw($MID_EXTRACT); sub lcat_folder ($$$) { my ($lei, $lms, $folder) = @_; - $lms //= $lei->{lse}->lms // return; + $lms //= $lei->lms or return; my $folders = [ $folder]; my $err = $lms->arg2folder($lei, $folders); $lei->qerr(@{$err->{qerr}}) if $err && $err->{qerr}; @@ -29,7 +29,7 @@ sub lcat_folder ($$$) { sub lcat_imap_uri ($$) { my ($lei, $uri) = @_; - my $lms = $lei->{lse}->lms or return; + my $lms = $lei->lms or return; # cf. LeiXsearch->lcat_dump if (defined $uri->uid) { my $oidhex = $lms->imap_oid($lei, $uri); @@ -129,8 +129,7 @@ sub lei_lcat { my ($lei, @argv) = @_; my $lxs = $lei->lxs_prepare or return; $lei->ale->refresh_externals($lxs, $lei); - my $sto = $lei->_lei_store(1); - $lei->{lse} = $sto->search; + $lei->_lei_store(1); my $opt = $lei->{opt}; my %mset_opt = map { $_ => $opt->{$_} } qw(threads limit offset); $mset_opt{asc} = $opt->{'reverse'} ? 1 : 0; @@ -153,8 +152,7 @@ no args allowed on command-line with --stdin sub _complete_lcat { my ($lei, @argv) = @_; - my $sto = $lei->_lei_store or return; - my $lms = $sto->search->lms or return; + my $lms = $lei->lms or return; my $match_cb = $lei->complete_url_prepare(\@argv); map { $match_cb->($_) } $lms->folders; } diff --git a/lib/PublicInbox/LeiLsMailSource.pm b/lib/PublicInbox/LeiLsMailSource.pm index cadc61ed..2d8913ac 100644 --- a/lib/PublicInbox/LeiLsMailSource.pm +++ b/lib/PublicInbox/LeiLsMailSource.pm @@ -103,8 +103,7 @@ sub _complete_ls_mail_source { my $match_cb = $lei->complete_url_prepare(\@argv); my @m = map { $match_cb->($_) } $lei->url_folder_cache->keys; my %f = map { $_ => 1 } @m; - my $sto = $lei->_lei_store; - if (my $lms = $sto ? $sto->search->lms : undef) { + if (my $lms = $lei->lms) { @m = map { $match_cb->($_) } grep( m!\A(?:imaps?|nntps?|s?news)://!, $lms->folders); @f{@m} = @m;