1 # Copyright (C) 2018-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use Compress::Zlib qw(compress);
7 use PublicInbox::TestCommon;
8 require_mods('DBD::SQLite');
9 use_ok 'PublicInbox::OverIdx';
10 my ($tmpdir, $for_destroy) = tmpdir();
11 my $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
13 is($over->max, 0, 'max is zero on new DB (scalar context)');
14 is_deeply([$over->max], [0], 'max is zero on new DB (list context)');
15 my $x = $over->next_tid;
16 is(int($x), $x, 'integer tid');
17 my $y = $over->next_tid;
18 is($y, $x+1, 'tid increases');
20 $x = $over->sid('hello-world');
21 is(int($x), $x, 'integer sid');
22 $y = $over->sid('hello-WORLD');
23 is($y, $x+1, 'sid increases');
24 is($over->sid('hello-world'), $x, 'idempotent');
25 ok(!$over->{dbh}->{ReadOnly}, 'OverIdx is not ReadOnly');
28 $over = PublicInbox::Over->new("$tmpdir/over.sqlite3");
30 ok($over->{dbh}->{ReadOnly}, 'Over is ReadOnly');
32 $over = PublicInbox::OverIdx->new("$tmpdir/over.sqlite3");
34 is($over->sid('hello-world'), $x, 'idempotent across reopen');
35 $over->each_by_mid('never', sub { fail('should not be called') });
37 $x = $over->create_ghost('never');
38 is(int($x), $x, 'integer tid for ghost');
39 $y = $over->create_ghost('NEVAR');
40 is($y, $x + 1, 'integer tid for ghost increases');
42 my $ddd = compress('');
43 foreach my $s ('', undef) {
44 $over->add_over([0, 0, 98, [ 'a' ], [], $s, $ddd]);
45 $over->add_over([0, 0, 99, [ 'b' ], [], $s, $ddd]);
46 my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
47 is_deeply([98], $msgs,
48 'messages not linked by empty subject');
51 $over->add_over([0, 0, 98, [ 'a' ], [], 's', $ddd]);
52 $over->add_over([0, 0, 99, [ 'b' ], [], 's', $ddd]);
53 foreach my $mid (qw(a b)) {
54 my $msgs = [ map { $_->{num} } @{$over->get_thread('a')} ];
55 is_deeply([98, 99], $msgs, 'linked messages by subject');
57 $over->add_over([0, 0, 98, [ 'a' ], [], 's', $ddd]);
58 $over->add_over([0, 0, 99, [ 'b' ], ['a'], 'diff', $ddd]);
59 foreach my $mid (qw(a b)) {
60 my $msgs = [ map { $_->{num} } @{$over->get_thread($mid)} ];
61 is_deeply([98, 99], $msgs, "linked messages by Message-ID: <$mid>");
63 isnt($over->max, 0, 'max is non-zero');