]> uap-core.de Git - rssreader.git/commitdiff
prepare item cleanup
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 13 Sep 2025 15:26:12 +0000 (17:26 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 13 Sep 2025 15:26:12 +0000 (17:26 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/ConfigWindow.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/Settings.kt

index ee11ef8f3fc095faa5bee27f0d25a1116a92498b..8cd893bb7c6f5ec8f90d84fca7e14667f3b02522 100644 (file)
@@ -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() {
index d0b74444f8d5adc1333f8790d9ccaeb45fda8748..ae30a011ef5a1ade77db8f1a33f410f73888c42b 100644 (file)
@@ -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()
+            }
+        }
+    }
 }
index 4f2061d3ad961e302e8477f42e3e38d81960b57d..d320848b97078b1016fe2d7c91d73974483db32f 100644 (file)
@@ -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