From: Olaf Wintermann Date: Sat, 13 Sep 2025 15:26:12 +0000 (+0200) Subject: prepare item cleanup X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=87f2cef83caca6be16f9836e567df75d4f72cf08;p=rssreader.git prepare item cleanup --- diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/ConfigWindow.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/ConfigWindow.kt index ee11ef8..8cd893b 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/ConfigWindow.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/ConfigWindow.kt @@ -13,6 +13,7 @@ class ConfigWindow { val defaultUpdateInterval: UiInteger val minUpdateWaitTime: UiInteger val autoUpdateStartDelay: UiInteger + val maxItemAge: UiInteger val message: UiString @@ -27,6 +28,7 @@ class ConfigWindow { defaultUpdateInterval = window.ui.integer() minUpdateWaitTime = window.ui.integer() autoUpdateStartDelay = window.ui.integer() + maxItemAge = window.ui.integer() message = window.ui.string() @@ -43,19 +45,24 @@ class ConfigWindow { } row { - rlabel("Default Update Interval") + rlabel("Default Update Interval (Seconds)") spinbox(intValue = defaultUpdateInterval, min = 0.0, max = 1000000.0) } row { - rlabel("Minimum Update Wait Time") + rlabel("Minimum Update Wait Time (Seconds)") spinbox(intValue = minUpdateWaitTime, min = 0.0, max = 1000000.0) } row { - rlabel("Auto Update Start Delay") + rlabel("Auto Update Start Delay (Seconds)") spinbox(intValue = autoUpdateStartDelay, min = 0.0, max = 1000000.0) } + + row { + rlabel("Max Item Age (Days)") + spinbox(intValue = maxItemAge, min = 0.0, max = 200000.0) + } } grid(margin = 12, rowspacing = 12) { row { @@ -84,6 +91,7 @@ class ConfigWindow { defaultUpdateInterval.setIntValue(App.settings.defaultRefreshInterval) minUpdateWaitTime.setIntValue(App.settings.minRefreshWaitTime) autoUpdateStartDelay.setIntValue(App.settings.autoRefreshStartDelay) + maxItemAge.setIntValue(App.settings.maxItemAge) } fun save() { @@ -92,6 +100,7 @@ class ConfigWindow { App.settings.defaultRefreshInterval = defaultUpdateInterval.intValue() App.settings.minRefreshWaitTime = minUpdateWaitTime.intValue() App.settings.autoRefreshStartDelay = autoUpdateStartDelay.intValue() + App.settings.maxItemAge = maxItemAge.intValue() } fun show() { 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 d0b7444..ae30a01 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -65,6 +65,7 @@ object Database { pos INT default 0, name VARCHAR, update_interval INT, + max_item_age INT DEFAULT 0, item_state_mode INT DEFAULT 0 ) """.trimIndent()) @@ -422,4 +423,29 @@ object Database { } return seconds } + + public fun cleanupItems(defaultMaxItemAge: Int) { + dataSource.connection.use { conn -> + conn.prepareStatement(""" + delete from items where item_id in ( + select item_id + from (select i.item_id, + c.name, + f.feed_id, + c.max_item_age, + datediff('dd', coalesce(updated, pub_date), now()) as age, + case when c.max_item_age > 0 then c.max_item_age else ? end as max_age + from items i + inner join feeds f on i.feed_id = f.feed_id + inner join feedcollections c on f.feedcollection_id = c.feedcollection_id + where i.is_bookmarked = false + and c.max_item_age >= 0) + where age > max_age + ) + """.trimIndent()).use { stmt -> + stmt.setInt(1, defaultMaxItemAge) + stmt.execute() + } + } + } } diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/Settings.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/Settings.kt index 4f2061d..d320848 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Settings.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Settings.kt @@ -13,6 +13,7 @@ class Settings { var autoRefreshStartDelay = 10 var defaultRefreshInterval = 3600 var minRefreshWaitTime = 60 + var maxItemAge = 0 fun load() { val filePath = Toolkit.getConfigFilePath("rssreader.properties") @@ -49,6 +50,12 @@ class Settings { e.printStackTrace() } } + val maxItemAge = properties.getProperty("MaxItemAge") + maxItemAge?.let { + try { + this.maxItemAge = it.toInt() + } catch (e: NumberFormatException) {} + } } else { println("create new file: $filePath") store(file) @@ -62,6 +69,7 @@ class Settings { AutoRefreshStartDelay = $autoRefreshStartDelay DefaultRefreshInterval = $defaultRefreshInterval MinRefreshWaitTime = $minRefreshWaitTime + MaxItemAge = $maxItemAge """.trimIndent()) } } \ No newline at end of file