about summary refs log tree commit homepage
path: root/lib/PublicInbox/Search.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-12-25 07:51:04 +0000
committerEric Wong <e@80x24.org>2019-12-28 19:38:23 +0000
commitf2364c5765f0692d2f1e82b61804359a38f3fdfc (patch)
tree2b0507af4558629169cc5ea1e48efd79cb8f015f /lib/PublicInbox/Search.pm
parentb316f7541ec263fd04ea50530a1d500f43773299 (diff)
downloadpublic-inbox-f2364c5765f0692d2f1e82b61804359a38f3fdfc.tar.gz
This allows callers to pass named (not anonymous) subs.

Update all retry_reopen callers to use this feature, and
fix some places where we failed to use retry_reopen :x
Diffstat (limited to 'lib/PublicInbox/Search.pm')
-rw-r--r--lib/PublicInbox/Search.pm16
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index 65c6ee83..eb1a1446 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -231,15 +231,15 @@ sub query {
 }
 
 sub retry_reopen {
-        my ($self, $cb) = @_;
+        my ($self, $cb, $arg) = @_;
         for my $i (1..10) {
                 if (wantarray) {
                         my @ret;
-                        eval { @ret = $cb->() };
+                        eval { @ret = $cb->($arg) };
                         return @ret unless $@;
                 } else {
                         my $ret;
-                        eval { $ret = $cb->() };
+                        eval { $ret = $cb->($arg) };
                         return $ret unless $@;
                 }
                 # Exception: The revision being read has been discarded -
@@ -259,11 +259,11 @@ sub retry_reopen {
 
 sub _do_enquire {
         my ($self, $query, $opts) = @_;
-        retry_reopen($self, sub { _enquire_once($self, $query, $opts) });
+        retry_reopen($self, \&_enquire_once, [ $self, $query, $opts ]);
 }
 
-sub _enquire_once {
-        my ($self, $query, $opts) = @_;
+sub _enquire_once { # retry_reopen callback
+        my ($self, $query, $opts) = @{$_[0]};
         my $xdb = xdb($self);
         my $enquire = $X{Enquire}->new($xdb);
         $enquire->set_query($query);
@@ -281,9 +281,7 @@ sub _enquire_once {
         my $limit = $opts->{limit} || 50;
         my $mset = $enquire->get_mset($offset, $limit);
         return $mset if $opts->{mset};
-        my @msgs = map {
-                PublicInbox::SearchMsg->load_doc($_->get_document);
-        } $mset->items;
+        my @msgs = map { PublicInbox::SearchMsg::from_mitem($_) } $mset->items;
         return \@msgs unless wantarray;
 
         ($mset->get_matches_estimated, \@msgs)