]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/OverIdx.pm
searchidx: fix incremental index with indexlevel=basic on v1
[public-inbox.git] / lib / PublicInbox / OverIdx.pm
index 62fec0dafb4056118a320ca3fe5ba42030b1fa33..bb3068ddcb4b190bcd30f4e24158d962bfa04751 100644 (file)
@@ -79,8 +79,15 @@ sub mid2id {
 }
 
 sub delete_by_num {
-       my ($self, $num) = @_;
+       my ($self, $num, $tid_ref) = @_;
        my $dbh = $self->{dbh};
+       if ($tid_ref) {
+               my $sth = $dbh->prepare_cached(<<'', undef, 1);
+SELECT tid FROM over WHERE num = ? LIMIT 1
+
+               $sth->execute($num);
+               $$tid_ref = $sth->fetchrow_array; # may be undef
+       }
        foreach (qw(over id2num)) {
                $dbh->prepare_cached(<<"")->execute($num);
 DELETE FROM $_ WHERE num = ?
@@ -262,7 +269,7 @@ sub add_over {
        my $vivified = 0;
 
        $self->begin_lazy;
-       $self->delete_by_num($num);
+       $self->delete_by_num($num, \$old_tid);
        foreach my $mid (@$mids) {
                my $v = 0;
                each_by_mid($self, $mid, ['tid'], sub {
@@ -310,14 +317,21 @@ sub delete_articles {
        $self->delete_by_num($_) foreach @$nums;
 }
 
+# returns number of removed messages
+# $oid may be undef to match only on $mid
 sub remove_oid {
        my ($self, $oid, $mid) = @_;
+       my $nr = 0;
        $self->begin_lazy;
        each_by_mid($self, $mid, ['ddd'], sub {
                my ($smsg) = @_;
-               $self->delete_by_num($smsg->{num}) if $smsg->{blob} eq $oid;
+               if (!defined($oid) || $smsg->{blob} eq $oid) {
+                       $self->delete_by_num($smsg->{num});
+                       $nr++;
+               }
                1;
        });
+       $nr;
 }
 
 sub create_tables {