]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Msgmap.pm
treewide: run update-copyrights from gnulib for 2019
[public-inbox.git] / lib / PublicInbox / Msgmap.pm
index 0035c9e3dc1ad8ff5bad1d3201ab06ecf9105032..9523752e9af07f8b973ac45d5a5aeda408801513 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2015-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # bidirectional Message-ID <-> Article Number mapping for the NNTP
@@ -126,9 +126,9 @@ sub mid_insert {
        my ($self, $mid) = @_;
        my $dbh = $self->{dbh};
        my $sth = $dbh->prepare_cached(<<'');
-INSERT OR IGNORE INTO msgmap (mid) VALUES (?)
+INSERT INTO msgmap (mid) VALUES (?)
 
-       return if $sth->execute($mid) == 0;
+       return unless eval { $sth->execute($mid) };
        my $num = $dbh->last_insert_id(undef, undef, 'msgmap', 'num');
        $self->num_highwater($num) if defined($num);
        $num;
@@ -211,11 +211,12 @@ ORDER BY num ASC LIMIT 1000
 }
 
 sub msg_range {
-       my ($self, $beg, $end) = @_;
+       my ($self, $beg, $end, $cols) = @_;
+       $cols //= 'num,mid';
        my $dbh = $self->{dbh};
        my $attr = { Columns => [] };
-       my $mids = $dbh->selectall_arrayref(<<'', $attr, $$beg, $end);
-SELECT num,mid FROM msgmap WHERE num >= ? AND num <= ?
+       my $mids = $dbh->selectall_arrayref(<<"", $attr, $$beg, $end);
+SELECT $cols FROM msgmap WHERE num >= ? AND num <= ?
 ORDER BY num ASC LIMIT 1000
 
        $$beg = $mids->[-1]->[0] + 1 if @$mids;