$pr->("I: rethread culled $total ghosts\n") if $pr && $total;
}
+# used for cross-inbox search
+sub eidx_prep ($) {
+ my ($self) = @_;
+ $self->{-eidx_prep} //= do {
+ my $dbh = $self->dbh;
+ $dbh->do(<<"");
+INSERT OR IGNORE INTO counter (key) VALUES ('eidx_docid')
+
+ $dbh->do(<<'');
+CREATE TABLE IF NOT EXISTS inboxes (
+ ibx_id INTEGER PRIMARY KEY AUTOINCREMENT,
+ eidx_key VARCHAR(255) NOT NULL, /* {newsgroup} // {inboxdir} */
+ UNIQUE (eidx_key)
+)
+
+ $dbh->do(<<'');
+CREATE TABLE IF NOT EXISTS xref3 (
+ docid INTEGER NOT NULL, /* <=> over.num */
+ ibx_id INTEGER NOT NULL, /* <=> inboxes.ibx_id */
+ xnum INTEGER NOT NULL, /* NNTP article number in ibx */
+ oidbin VARBINARY NOT NULL, /* 20-byte SHA-1 or 32-byte SHA-256 */
+ UNIQUE (docid, ibx_id, xnum, oidbin)
+)
+
+ $dbh->do('CREATE INDEX IF NOT EXISTS idx_docid ON xref3 (docid)');
+
+ $dbh->do(<<'');
+CREATE TABLE IF NOT EXISTS eidx_meta (
+ key VARCHAR(255) PRIMARY KEY,
+ val VARCHAR(255) NOT NULL
+)
+
+ $dbh;
+ };
+}
+
+sub eidx_meta { # requires transaction
+ my ($self, $key, $val) = @_;
+
+ my $sql = 'SELECT val FROM eidx_meta WHERE key = ? LIMIT 1';
+ my $dbh = $self->{dbh};
+ defined($val) or return $dbh->selectrow_array($sql, undef, $key);
+
+ my $prev = $dbh->selectrow_array($sql, undef, $key);
+ if (defined $prev) {
+ $sql = 'UPDATE eidx_meta SET val = ? WHERE key = ?';
+ $dbh->do($sql, undef, $val, $key);
+ } else {
+ $sql = 'INSERT INTO eidx_meta (key,val) VALUES (?,?)';
+ $dbh->do($sql, undef, $key, $val);
+ }
+ $prev;
+}
+
+sub eidx_max {
+ my ($self) = @_;
+ get_counter($self->{dbh}, 'eidx_docid');
+}
+
+sub add_xref3 {
+ my ($self, $docid, $xnum, $oidhex, $eidx_key) = @_;
+ begin_lazy($self);
+ my $ibx_id = id_for($self, 'inboxes', 'ibx_id', eidx_key => $eidx_key);
+ my $oidbin = pack('H*', $oidhex);
+ my $sth = $self->{dbh}->prepare_cached(<<'');
+INSERT OR IGNORE INTO xref3 (docid, ibx_id, xnum, oidbin) VALUES (?, ?, ?, ?)
+
+ $sth->bind_param(1, $docid);
+ $sth->bind_param(2, $ibx_id);
+ $sth->bind_param(3, $xnum);
+ $sth->bind_param(4, $oidbin, SQL_BLOB);
+ $sth->execute;
+}
+
+sub remove_xref3 {
+ my ($self, $docid, $oidhex, $eidx_key) = @_;
+ begin_lazy($self);
+ my $ibx_id = id_for($self, 'inboxes', 'ibx_id', eidx_key => $eidx_key);
+ my $oidbin = pack('H*', $oidhex);
+ my $sth = $self->{dbh}->prepare_cached(<<'');
+DELETE FROM xref3 WHERE docid = ? AND ibx_id = ? AND oidbin = ?
+
+ $sth->bind_param(1, $docid);
+ $sth->bind_param(2, $ibx_id);
+ $sth->bind_param(3, $oidbin, SQL_BLOB);
+ $sth->execute;
+}
+
1;