aboutsummaryrefslogtreecommitdiff
path: root/app/Models/EntryDAO.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2021-02-02 00:03:59 +0100
committerGravatar GitHub <noreply@github.com> 2021-02-02 00:03:59 +0100
commit1ee1fcce91d64c8cee6b8621aaedbdeae0c9c330 (patch)
tree2359a744b9711cd5bd51d168461333095d4a64c2 /app/Models/EntryDAO.php
parent8285f1df43ce19bbd533c70c3fd1487908883725 (diff)
INSERT ... ON CONFLIT DO NOTHING for addEntry (#3409)
#fix https://github.com/FreshRSS/FreshRSS/issues/3402 Explicit `INSERT OR IGNORE` / `ON CONFLICT DO NOTHING` for the `addEntry()` method, which does expect some duplicates.
Diffstat (limited to 'app/Models/EntryDAO.php')
-rw-r--r--app/Models/EntryDAO.php9
1 files changed, 7 insertions, 2 deletions
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 28a9b8bde..6f7a4b48f 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -18,6 +18,10 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
return 'hex(' . $x . ')';
}
+ public function sqlIgnoreConflict($sql) {
+ return str_replace('INSERT INTO ', 'INSERT IGNORE INTO ', $sql);
+ }
+
//TODO: Move the database auto-updates to DatabaseDAO
protected function createEntryTempTable() {
$ok = false;
@@ -83,14 +87,15 @@ SQL;
public function addEntry($valuesTmp, $useTmpTable = true) {
if ($this->addEntryPrepared == null) {
- $sql = 'INSERT INTO `_' . ($useTmpTable ? 'entrytmp' : 'entry') . '` (id, guid, title, author, '
+ $sql = $this->sqlIgnoreConflict(
+ 'INSERT INTO `_' . ($useTmpTable ? 'entrytmp' : 'entry') . '` (id, guid, title, author, '
. ($this->isCompressed() ? 'content_bin' : 'content')
. ', link, date, `lastSeen`, hash, is_read, is_favorite, id_feed, tags) '
. 'VALUES(:id, :guid, :title, :author, '
. ($this->isCompressed() ? 'COMPRESS(:content)' : ':content')
. ', :link, :date, :last_seen, '
. $this->sqlHexDecode(':hash')
- . ', :is_read, :is_favorite, :id_feed, :tags)';
+ . ', :is_read, :is_favorite, :id_feed, :tags)');
$this->addEntryPrepared = $this->pdo->prepare($sql);
}
if ($this->addEntryPrepared) {