user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] msgmap: mid_insert ignores duplicates instead of die-ing
@ 2017-06-22 22:01 Eric Wong
  2017-06-23  1:21 ` [PATCH 2/1] msgmap: ignore duplicates instead of dying Eric Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2017-06-22 22:01 UTC (permalink / raw)
  To: meta

This will allow smoother imports as occasional Message-ID
duplicates happen and the best we can do is ignore the
second one.
---
 lib/PublicInbox/Msgmap.pm | 6 +++---
 t/msgmap.t                | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm
index 3fb3805..a49b61e 100644
--- a/lib/PublicInbox/Msgmap.pm
+++ b/lib/PublicInbox/Msgmap.pm
@@ -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');
 }
 
diff --git a/t/msgmap.t b/t/msgmap.t
index 5c28e54..a5232fa 100644
--- a/t/msgmap.t
+++ b/t/msgmap.t
@@ -27,9 +27,9 @@ foreach my $mid (@mids) {
 }
 
 $@ = undef;
-eval { $d->mid_insert('a@b') };
-ok($@, 'error raised when attempting duplicate message ID');
-
+my $ret = $d->mid_insert('a@b');
+is($ret, undef, 'duplicate mid_insert in undef result');
+is($d->num_for('a@b'), $mid2num{'a@b'}, 'existing number not clobbered');
 
 foreach my $n (keys %num2mid) {
 	is($d->mid_for($n), $num2mid{$n}, "num:$n maps correctly");
-- 
EW


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/1] msgmap: ignore duplicates instead of dying
  2017-06-22 22:01 [PATCH] msgmap: mid_insert ignores duplicates instead of die-ing Eric Wong
@ 2017-06-23  1:21 ` Eric Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2017-06-23  1:21 UTC (permalink / raw)
  To: meta

This prevents public-inbox-watch from dying when reloading
(and thus rescanning) already-imported directories.
---
 lib/PublicInbox/Msgmap.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm
index a49b61e..7e0f34a 100644
--- a/lib/PublicInbox/Msgmap.pm
+++ b/lib/PublicInbox/Msgmap.pm
@@ -179,7 +179,7 @@ sub id_batch {
 sub mid_set {
 	my ($self, $num, $mid) = @_;
 	my $sth = $self->{mid_set} ||= do {
-		my $sql = 'INSERT INTO msgmap (num, mid) VALUES (?,?)';
+		my $sql = 'INSERT OR IGNORE INTO msgmap (num, mid) VALUES (?,?)';
 		$self->{dbh}->prepare($sql);
 	};
 	$sth->execute($num, $mid);
-- 
EW

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-06-23  1:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-22 22:01 [PATCH] msgmap: mid_insert ignores duplicates instead of die-ing Eric Wong
2017-06-23  1:21 ` [PATCH 2/1] msgmap: ignore duplicates instead of dying Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).