]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Msgmap.pm
msgmap: mid_insert ignores duplicates instead of die-ing
[public-inbox.git] / lib / PublicInbox / Msgmap.pm
index 3fb3805fe82abea0c23684890d1f33004e6815d5..a49b61e8b7f3636eb28cba61ca052c5000b5720c 100644 (file)
@@ -82,10 +82,10 @@ sub created_at {
 sub mid_insert {
        my ($self, $mid) = @_;
        my $dbh = $self->{dbh};
-       use constant MID_INSERT => 'INSERT INTO msgmap (mid) VALUES (?)';
-       my $sth = $self->{mid_insert} ||= $dbh->prepare(MID_INSERT);
+       my $sql = 'INSERT OR IGNORE INTO msgmap (mid) VALUES (?)';
+       my $sth = $self->{mid_insert} ||= $dbh->prepare($sql);
        $sth->bind_param(1, $mid);
-       $sth->execute;
+       return if $sth->execute == 0;
        $dbh->last_insert_id(undef, undef, 'msgmap', 'num');
 }