From 47f556d0d86b8478639ed49d23babdc835be3e46 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Mon, 8 Dec 2025 15:33:11 +0100 Subject: [PATCH] fix url merge in updateFeedCollection, update sourcelist after feed update --- .../kotlin/de/unixwork/rssreader/Database.kt | 56 ++++++++++++++++--- .../de/unixwork/rssreader/FeedConfig.kt | 33 ++++++----- .../de/unixwork/rssreader/MainWindow.kt | 1 + 3 files changed, 67 insertions(+), 23 deletions(-) diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt index 7defdf6..51415c1 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -307,28 +307,66 @@ object Database { stmt.execute() } - uris.forEach { uri -> - // disable all feeds first and then re-activate all feeds from the uri list - conn.prepareStatement("update feeds set disabled = TRUE where feedcollection_id = ?").use { stmt -> + var updateList = true + // check if the old and new list only contain a single uri + if(uris.size == 1) { + conn.prepareStatement("select count(*) from feeds where feedcollection_id = ? and disabled = FALSE").use { stmt -> stmt.setInt(1, feed.id) + stmt.executeQuery().use { rs -> + if(rs.next() && rs.getInt(1) == 1) { + updateList = false + } + } + } + } + + if(updateList) { + // disable all feeds first and then re-activate all feeds from the uri list + conn.prepareStatement(""" + update feeds set auth_user = ?, auth_password = ?, certpath = ?, disabled = TRUE + where feedcollection_id = ? + """.trimIndent()).use { stmt -> + stmt.setString(1, user) + stmt.setString(2, password) + stmt.setString(3, cert) + stmt.setInt(4, feed.id) stmt.execute() } + // merge url list + uris.forEach { uri -> + conn.prepareStatement(""" + merge into feeds f + using (select cast(? as int) as feedcollection_id, cast(? as varchar) as url) v + on (f.feedcollection_id = v.feedcollection_id and f.url = v.url) + when matched then update set + f.disabled = false + when not matched then insert(feedcollection_id, url, auth_user, auth_password, certpath) + values (v.feedcollection_id, v.url, ?, ?, ?) + """.trimMargin()).use { stmt -> + stmt.setInt(1, feed.id) + stmt.setString(2, uri) + stmt.setString(3, user) + stmt.setString(4, password) + stmt.setString(5, cert) + stmt.execute() + } + } + } else { + // just update the single feed conn.prepareStatement(""" update feeds set url = ?, auth_user = ?, auth_password = ?, - certpath = ?, - disabled = FALSE - where feedcollection_id = ? and url = ? - """.trimMargin()).use { stmt -> - stmt.setString(1, uri) + certpath = ? + where feedcollection_id = ? + """.trimIndent()).use { stmt -> + stmt.setString(1, uris.first()) stmt.setString(2, user) stmt.setString(3, password) stmt.setString(4, cert) stmt.setInt(5, feed.id) - stmt.setString(6, uri) stmt.execute() } } diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt index 538206c..90df0dc 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt @@ -208,6 +208,15 @@ class FeedConfig(toplevel: Toplevel) { itemStateMode = 0 } println("groupSel: ${groups.selectedIndex}, feedName: $feedName, urlStr: $urlStr") + var u:String? = user.toString() + var p:String? = password.toString() + + if(u?.isEmpty() == true) { + u = null + } + if(p?.isEmpty() == true) { + p = null + } parent?.let { FeedConfig.PreviousGroup = it try { @@ -215,9 +224,9 @@ class FeedConfig(toplevel: Toplevel) { parent = it, name = feedName, uris = uris, - user = user.toString(), - password = password.toString(), - cert = cert.toString(), + user = u, + password = p, + cert = null, //cert.toString(), internalBrowser = internalBrowser, updateInterval = updateIntv, maxItemAge = maxItemAge, @@ -235,7 +244,6 @@ class FeedConfig(toplevel: Toplevel) { } public fun updateFeed() { - val parent = groups.selected val feedName = name.toString() val urlStr = urls.toString() val uris = urlStr.split("\n").map { it.trim() }.filter { it.isNotBlank() } @@ -258,17 +266,14 @@ class FeedConfig(toplevel: Toplevel) { itemStateMode = 0 } - var user: String? = null - var password: String? = null - var cert: String? = null + var u:String? = user.toString() + var p:String? = password.toString() - val u = user.toString() - val p = password.toString() - if(u.isNotBlank()) { - user = u + if(u?.isEmpty() == true) { + u = null } - if(p.isNotBlank()) { - password = p + if(p?.isEmpty() == true) { + p = null } feedCollection?.let { @@ -278,7 +283,7 @@ class FeedConfig(toplevel: Toplevel) { it.internalBrowser = internalBrowser it.maxItemAge = maxItemAge try { - Database.updateFeedCollection(it, uris, user, password, cert) + Database.updateFeedCollection(it, uris, u, p, null) } catch (e: Exception) { e.printStackTrace() } diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt index 37a373e..89e4229 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt @@ -448,6 +448,7 @@ class MainWindow() { feedConfig?.updateFeed() } ev.`object`.close() + //sourceList.updateFeeds() }, ui = null) feedConfig = FeedConfig(w) -- 2.47.3