]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ExtSearchIdx.pm
searchidx: remove xref3 support for Xapian
[public-inbox.git] / lib / PublicInbox / ExtSearchIdx.pm
index 32c5718817d6703c4a4d625e03c9c31c8f546dae..026e137730fd8610aed8043cc65b8dd75e319462 100644 (file)
@@ -19,10 +19,12 @@ use v5.10.1;
 use parent qw(PublicInbox::ExtSearch PublicInbox::Lock);
 use Carp qw(croak carp);
 use PublicInbox::Search;
-use PublicInbox::SearchIdx qw(crlf_adjust);
+use PublicInbox::SearchIdx qw(crlf_adjust prepare_stack);
 use PublicInbox::OverIdx;
+use PublicInbox::MID qw(mids);
 use PublicInbox::V2Writable;
 use PublicInbox::InboxWritable;
+use PublicInbox::ContentHash qw(content_hash);
 use PublicInbox::Eml;
 use File::Spec;
 
@@ -54,6 +56,7 @@ sub new {
 
 sub attach_inbox {
        my ($self, $ibx) = @_;
+       $ibx = PublicInbox::InboxWritable->new($ibx);
        my $key = $ibx->eidx_key;
        if (!$ibx->over || !$ibx->mm) {
                warn "W: skipping $key (unindexed)\n";
@@ -113,14 +116,15 @@ sub do_xpost ($$) {
        my $eml = $req->{eml};
        if (my $new_smsg = $req->{new_smsg}) { # 'm' on cross-posted message
                my $xnum = $req->{xnum};
-               $idx->shard_add_xref3($docid, $xnum, $oid, $xibx, $eml);
+               $self->{oidx}->add_xref3($docid, $xnum, $oid, $xibx->eidx_key);
+               $idx->shard_add_eidx_info($docid, $oid, $xibx, $eml);
        } else { # 'd'
-               $idx->shard_remove_xref3($docid, $oid, $xibx, $eml);
+               $idx->shard_remove_eidx_info($docid, $oid, $xibx, $eml);
        }
 }
 
 # called by V2Writable::sync_prepare
-sub artnum_max { $_[0]->{oidx}->get_counter('eidx_docid') }
+sub artnum_max { $_[0]->{oidx}->eidx_max }
 
 sub index_unseen ($) {
        my ($req) = @_;
@@ -132,7 +136,10 @@ sub index_unseen ($) {
        $new_smsg->{num} = $docid;
        my $idx = $self->idx_shard($docid);
        $self->{oidx}->add_overview($eml, $new_smsg);
-       $idx->index_raw(undef, $eml, $new_smsg, $req->{ibx});
+       my $oid = $new_smsg->{blob};
+       my $ibx = delete $req->{ibx} or die 'BUG: {ibx} unset';
+       $self->{oidx}->add_xref3($docid, $req->{xnum}, $oid, $ibx->eidx_key);
+       $idx->index_raw(undef, $eml, $new_smsg, $ibx);
 }
 
 sub do_finalize ($) {
@@ -174,7 +181,7 @@ sub ck_existing { # git->cat_async callback
        my $smsg = $req->{cur_smsg} or die 'BUG: {cur_smsg} missing';
        return if is_bad_blob($oid, $type, $size, $smsg->{blob});
        my $cur = PublicInbox::Eml->new($bref);
-       if (content_digest($cur) eq $req->{chash}) {
+       if (content_hash($cur) eq $req->{chash}) {
                push @{$req->{indexed}}, $smsg; # for do_xpost
        } # else { index_unseen later }
        do_step($req);
@@ -248,12 +255,13 @@ sub _sync_inbox ($$$) {
                my $epoch_max;
                defined($ibx->git_dir_latest(\$epoch_max)) or return;
                $sync->{epoch_max} = $epoch_max;
-               sync_prepare($self, $sync) or return;
+               sync_prepare($self, $sync) or return; # fills $sync->{todo}
        } elsif ($v == 1) {
                my $uv = $ibx->uidvalidity;
                my $lc = $self->{oidx}->eidx_meta("lc-v1:$ekey//$uv");
                my $stk = prepare_stack($sync, $lc ? "$lc..HEAD" : 'HEAD');
                my $unit = { stack => $stk, git => $ibx->git };
+               push @{$sync->{todo}}, $unit;
        } else {
                warn "E: $ekey unsupported inbox version (v$v)\n";
                return;
@@ -267,10 +275,23 @@ sub eidx_sync { # main entry point
        $self->{oidx}->rethread_prepare($opt);
 
        _sync_inbox($self, $opt, $_) for (@{$self->{ibx_list}});
+
        $self->{oidx}->rethread_done($opt);
+
        PublicInbox::V2Writable::done($self);
 }
 
+sub update_last_commit {
+       my ($self, $sync, $unit, $latest_cmt) = @_;
+
+       my $ALL = $self->git;
+       # while (scalar(@{$ALL->{inflight_c}}) || scalar(@{$ALL->{inflight}})) {
+               # $ALL->check_async_wait;
+               # $ALL->cat_async_wait;
+       # }
+       # TODO
+}
+
 sub idx_init { # similar to V2Writable
        my ($self, $opt) = @_;
        return if $self->{idx_shards};
@@ -315,5 +336,6 @@ no warnings 'once';
 *index_todo = \&PublicInbox::V2Writable::index_todo;
 *count_shards = \&PublicInbox::V2Writable::count_shards;
 *atfork_child = \&PublicInbox::V2Writable::atfork_child;
+*idx_shard = \&PublicInbox::V2Writable::idx_shard;
 
 1;