From 3b8b9eabd037130b4c05d6b615bd9ad8f02cc59f Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Tue, 15 Aug 2017 10:44:54 +0200 Subject: commitNewEntries should ignore conflicting keys on migration from entrytmp to entry Fixes #1610 by first ignoring all entries from entrytmp which exists already inside the entry table. --- app/Models/EntryDAOPGSQL.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/Models/EntryDAOPGSQL.php') diff --git a/app/Models/EntryDAOPGSQL.php b/app/Models/EntryDAOPGSQL.php index b25993c47..f70c5f65c 100644 --- a/app/Models/EntryDAOPGSQL.php +++ b/app/Models/EntryDAOPGSQL.php @@ -30,7 +30,10 @@ maxrank bigint := (SELECT MAX(id) FROM `' . $this->prefix . 'entrytmp`); rank bigint := (SELECT maxrank - COUNT(*) FROM `' . $this->prefix . 'entrytmp`); BEGIN INSERT INTO `' . $this->prefix . 'entry` (id, guid, title, author, content, link, date, `lastSeen`, hash, is_read, is_favorite, id_feed, tags) - (SELECT rank + row_number() OVER(ORDER BY date) AS id, guid, title, author, content, link, date, `lastSeen`, hash, is_read, is_favorite, id_feed, tags FROM `' . $this->prefix . 'entrytmp` ORDER BY date); + (SELECT rank + row_number() OVER(ORDER BY date) AS id, guid, title, author, content, link, date, `lastSeen`, hash, is_read, is_favorite, id_feed, tags + FROM `' . $this->prefix . 'entrytmp` AS entrytmp + WHERE NOT EXISTS (SELECT 1 FROM `' . $this->prefix . 'entry` AS entry WHERE entrytmp.id_feed = entry.id_feed AND entrytmp.guid = entry.guid) + ORDER BY date); DELETE FROM `' . $this->prefix . 'entrytmp` WHERE id <= maxrank; END $$;'; $hadTransaction = $this->bd->inTransaction(); -- cgit v1.2.3 From 074ab63bb1e59d527576cb91ed2e9f484a37b216 Mon Sep 17 00:00:00 2001 From: Adrien Dorsaz Date: Tue, 15 Aug 2017 11:39:21 +0200 Subject: commitNewEntries: fixup to use unique aliases --- app/Models/EntryDAOPGSQL.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/Models/EntryDAOPGSQL.php') diff --git a/app/Models/EntryDAOPGSQL.php b/app/Models/EntryDAOPGSQL.php index f70c5f65c..6e6f9e658 100644 --- a/app/Models/EntryDAOPGSQL.php +++ b/app/Models/EntryDAOPGSQL.php @@ -31,8 +31,8 @@ rank bigint := (SELECT maxrank - COUNT(*) FROM `' . $this->prefix . 'entrytmp`); BEGIN INSERT INTO `' . $this->prefix . 'entry` (id, guid, title, author, content, link, date, `lastSeen`, hash, is_read, is_favorite, id_feed, tags) (SELECT rank + row_number() OVER(ORDER BY date) AS id, guid, title, author, content, link, date, `lastSeen`, hash, is_read, is_favorite, id_feed, tags - FROM `' . $this->prefix . 'entrytmp` AS entrytmp - WHERE NOT EXISTS (SELECT 1 FROM `' . $this->prefix . 'entry` AS entry WHERE entrytmp.id_feed = entry.id_feed AND entrytmp.guid = entry.guid) + FROM `' . $this->prefix . 'entrytmp` AS etmp + WHERE NOT EXISTS (SELECT 1 FROM `' . $this->prefix . 'entry` AS ereal WHERE etmp.id_feed = ereal.id_feed AND etmp.guid = ereal.guid) ORDER BY date); DELETE FROM `' . $this->prefix . 'entrytmp` WHERE id <= maxrank; END $$;'; -- cgit v1.2.3