1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # WQ worker for dealing with LeiImport IMAP flags on already-imported messages
6 package PublicInbox::LeiImportKw;
9 use parent qw(PublicInbox::IPC);
13 my $self = bless { -wq_ident => 'lei import_kw worker' }, $cls;
14 my $j = $self->detect_nproc // 4;
16 my ($op_c, $ops) = $lei->workers_start($self, $j);
17 $op_c->{ops} = $ops; # for PktOp->event_step
18 $self->{lei_sock} = $lei->{sock};
22 sub ipc_atfork_child {
24 my $lei = $self->{lei};
25 $lei->_lei_atfork_child;
26 my $net = delete $lei->{net} // die 'BUG: no lei->{net}';
27 $self->{sto} = $lei->{sto} // die 'BUG: no lei->{sto}';
28 $self->{verbose} = $lei->{opt}->{verbose};
29 $self->{lse} = $self->{sto}->search;
30 $self->{over} = $self->{lse}->over;
31 $self->{-lms_ro} = $net->{-lms_ro} || die 'BUG: net->{-lms_ro} FALSE';
32 $self->SUPER::ipc_atfork_child;
35 sub ck_update_kw { # via wq_io_do
36 my ($self, $url, $uid, $kw) = @_;
37 my @oidbin = $self->{-lms_ro}->num_oidbin($url, $uid);
38 my $uid_url = "$url/;UID=$uid";
39 @oidbin > 1 and warn("W: $uid_url not unique:\n",
40 map { "\t".unpack('H*', $_)."\n" } @oidbin);
42 my @docids = sort { $a <=> $b } grep { !$seen{$_}++ }
43 map { $self->{over}->oidbin_exists($_) } @oidbin;
44 $self->{lse}->kw_changed(undef, $kw, \@docids) or return;
45 $self->{verbose} and $self->{lei}->qerr("# $uid_url => @$kw\n");
46 $self->{sto}->wq_do('set_eml_vmd', undef, { kw => $kw }, \@docids);
49 sub _lei_wq_eof { # EOF callback for main lei daemon
51 my $ikw = delete $lei->{ikw} or return $lei->fail;
52 $lei->sto_done_request($ikw->{lei_sock});