]> uap-core.de Git - rssreader.git/commitdiff
allow items with the same guid
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 1 Sep 2025 18:46:34 +0000 (20:46 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 1 Sep 2025 18:46:34 +0000 (20:46 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt

index 3bdfd9f05f3e94b8ad4f51f178a26f86e4ea9fab..862cf734eebfc00a51ed3f5396329117599e81ce 100644 (file)
@@ -278,8 +278,9 @@ object Database {
         dataSource.connection.use { conn ->
             conn.prepareStatement("""
                     insert into items (feed_id, title, link, category, description, author, pub_date, updated, guid, contentText, contentHTML)
-                    select ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
-                    where ? not in (select guid from items) 
+                    select ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? from dual 
+                    left join items I on I.guid = ? and I.feed_id = ? and coalesce(I.updated, I.pub_date, ?) = ?
+                    where I.item_id is null
                 """.trimIndent()).use { stmt ->
                 items.forEach { item ->
                     stmt.setInt(1, item.feedId)
@@ -294,6 +295,10 @@ object Database {
                     stmt.setString(10, item.contentText)
                     stmt.setString(11, item.contentHtml)
                     stmt.setString(12, item.guid)
+                    stmt.setInt(13, item.feedId)
+                    val itemDate = java.sql.Timestamp.valueOf(item.updated ?: item.pubDate ?: java.time.LocalDateTime.MIN)
+                    stmt.setTimestamp(14, itemDate)
+                    stmt.setTimestamp(15, itemDate)
                     stmt.addBatch()
                 }
                 stmt.executeBatch()