about summary refs log tree commit homepage
path: root/lib/PublicInbox/V2Writable.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-04-06 21:44:38 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-04-06 21:45:03 +0000
commitfad9acd35e56a289ade90a62d056b2a6663d448c (patch)
tree74d3203af13690a521d4de54ca2733223e2c389e /lib/PublicInbox/V2Writable.pm
parent8f2999546c9447ce2aed48ba4d1192e0058e28a2 (diff)
downloadpublic-inbox-fad9acd35e56a289ade90a62d056b2a6663d448c.tar.gz
Favor simpler internal APIs this time around, this cuts
a fair amount of code out and takes another step towards
removing Xapian as a dependency for v2 repos.
Diffstat (limited to 'lib/PublicInbox/V2Writable.pm')
-rw-r--r--lib/PublicInbox/V2Writable.pm34
1 files changed, 14 insertions, 20 deletions
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index a8117aaa..877a4591 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -271,22 +271,20 @@ sub remove_internal {
 
         foreach my $mid (@$mids) {
                 my %gone;
-                $srch->reopen->each_smsg_by_mid($mid, sub {
-                        my ($smsg) = @_;
-                        $smsg->load_expand;
+                my ($id, $prev);
+                while (my $smsg = $srch->next_by_mid($mid, \$id, \$prev)) {
                         my $msg = $ibx->msg_by_smsg($smsg);
                         if (!defined($msg)) {
                                 warn "broken smsg for $mid\n";
-                                return 1; # continue
+                                next; # continue
                         }
                         my $orig = $$msg;
                         my $cur = PublicInbox::MIME->new($msg);
                         if (content_id($cur) eq $cid) {
                                 $smsg->{mime} = $cur;
-                                $gone{$smsg->num} = [ $smsg, \$orig ];
+                                $gone{$smsg->{num}} = [ $smsg, \$orig ];
                         }
-                        1; # continue
-                });
+                }
                 my $n = scalar keys %gone;
                 next unless $n;
                 if ($n > 1) {
@@ -552,26 +550,23 @@ sub lookup_content {
         my $srch = $ibx->search->reopen;
         my $cid = content_id($mime);
         my $found;
-        $srch->each_smsg_by_mid($mid, sub {
-                my ($smsg) = @_;
-                $smsg->load_expand;
+        my ($id, $prev);
+        while (my $smsg = $srch->next_by_mid($mid, \$id, \$prev)) {
                 my $msg = $ibx->msg_by_smsg($smsg);
                 if (!defined($msg)) {
                         warn "broken smsg for $mid\n";
-                        return 1; # continue
+                        next;
                 }
                 my $cur = PublicInbox::MIME->new($msg);
                 if (content_id($cur) eq $cid) {
                         $smsg->{mime} = $cur;
                         $found = $smsg;
-                        return 0; # break out of loop
+                        last;
                 }
 
                 # XXX DEBUG_DIFF is experimental and may be removed
                 diff($mid, $cur, $mime) if $ENV{DEBUG_DIFF};
-
-                1; # continue
-        });
+        }
         $found;
 }
 
@@ -770,15 +765,14 @@ sub unindex_oid {
         my $mime = PublicInbox::MIME->new($msgref);
         my $mids = mids($mime->header_obj);
         $mime = $msgref = undef;
-
+        my $srch = $self->{-inbox}->search;
         foreach my $mid (@$mids) {
                 my %gone;
-                $self->{-inbox}->search->reopen->each_smsg_by_mid($mid, sub {
-                        my ($smsg) = @_;
-                        $smsg->load_expand;
+                my ($id, $prev);
+                while (my $smsg = $srch->next_by_mid($mid, \$id, \$prev)) {
                         $gone{$smsg->num} = 1 if $oid eq $smsg->{blob};
                         1; # continue
-                });
+                }
                 my $n = scalar keys %gone;
                 next unless $n;
                 if ($n > 1) {