X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FMsgmap.pm;h=3887a9e6b2c2264a468e9f7903ecf1e68af14b47;hb=d7780e12856d83b9f5c58586691e2fbe711321ed;hp=5b4cebc105bd21c659b1182721323cbf881d381a;hpb=793dcb03635e167143c9df6897999f4698a5133c;p=public-inbox.git diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm index 5b4cebc1..3887a9e6 100644 --- a/lib/PublicInbox/Msgmap.pm +++ b/lib/PublicInbox/Msgmap.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2020 all contributors +# Copyright (C) 2015-2021 all contributors # License: AGPL-3.0+ # bidirectional Message-ID <-> Article Number mapping for the NNTP @@ -6,9 +6,10 @@ # numbers for NNTP and allows prefix lookups for partial Message-IDs # in case URLs get truncated from copy-n-paste errors by users. # -# This is maintained by ::SearchIdx +# This is maintained by ::SearchIdx (v1) and ::V2Writable (v2) package PublicInbox::Msgmap; use strict; +use v5.10.1; use DBI; use DBD::SQLite; use PublicInbox::Over; @@ -31,15 +32,11 @@ sub new_file { my $self = bless { filename => $f }, $class; my $dbh = $self->{dbh} = PublicInbox::Over::dbh_new($self, $rw); if ($rw) { - # TRUNCATE reduces I/O compared to the default (DELETE) - $dbh->do('PRAGMA journal_mode = TRUNCATE'); - $dbh->begin_work; create_tables($dbh); $self->created_at(time) unless $self->created_at; - my $max = $self->max // 0; - $self->num_highwater($max); + $self->num_highwater(max($self)); $dbh->commit; } $self; @@ -49,7 +46,7 @@ sub new_file { sub tmp_clone { my ($self, $dir) = @_; require File::Temp; - my $tmp = "mm_tmp-$$-XXXXXX"; + my $tmp = "mm_tmp-$$-XXXX"; my ($fh, $fn) = File::Temp::tempfile($tmp, EXLOCK => 0, DIR => $dir); PublicInbox::Spawn::nodatacow_fd(fileno($fh)); $self->{dbh}->sqlite_backup_to_file($fn); @@ -93,6 +90,7 @@ sub last_commit_xap { $self->meta_accessor("last_xap$version-$i", $commit); } +# this is the UIDVALIDITY for IMAP (cf. RFC 3501 sec 2.3.1.1. item 3) sub created_at { my ($self, $second) = @_; $self->meta_accessor('created_at', $second); @@ -145,7 +143,7 @@ sub max { my $sth = $_[0]->{dbh}->prepare_cached('SELECT MAX(num) FROM msgmap', undef, 1); $sth->execute; - $sth->fetchrow_array; + $sth->fetchrow_array // 0; } sub minmax { @@ -154,7 +152,7 @@ sub minmax { my $sth = $_[0]->{dbh}->prepare_cached('SELECT MIN(num) FROM msgmap', undef, 1); $sth->execute; - ($sth->fetchrow_array, max($_[0])); + ($sth->fetchrow_array // 0, max($_[0])); } sub mid_delete { @@ -191,17 +189,6 @@ CREATE TABLE IF NOT EXISTS meta ( } -# used by NNTP.pm -sub ids_after { - my ($self, $num) = @_; - my $ids = $self->{dbh}->selectcol_arrayref(<<'', undef, $$num); -SELECT num FROM msgmap WHERE num > ? -ORDER BY num ASC LIMIT 1000 - - $$num = $ids->[-1] if @$ids; - $ids; -} - sub msg_range { my ($self, $beg, $end, $cols) = @_; $cols //= 'num,mid';