]> uap-core.de Git - rssreader.git/commitdiff
add automatic item cleanup
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 22 Sep 2025 16:20:33 +0000 (18:20 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 22 Sep 2025 16:20:33 +0000 (18:20 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt

index 2e18ec73f5e3c4e320b5d21bffd9871ad2e28813..ef16805203fc7048ddd656fda2d92212cc798bf6 100644 (file)
@@ -16,6 +16,7 @@ import kotlinx.coroutines.delay
 import kotlinx.coroutines.launch
 import org.h2.api.H2Type.row
 import java.io.IOException
+import java.time.LocalDate
 
 object App : Application {
     var window: MainWindow? = null
@@ -109,6 +110,8 @@ object App : Application {
         GlobalScope.launch(Dispatchers.IO) {
             delay(delayedStart)
 
+            var lastDelete = LocalDate.MIN;
+
             while(true) {
                 println("Background sync")
                 try {
@@ -126,6 +129,14 @@ object App : Application {
                 }
                 println("Background sync done")
 
+                // delete old items if needed
+                val today = LocalDate.now()
+                if(lastDelete != today) {
+                    println("Cleanup Items")
+                    Database.cleanupItems(settings.maxItemAge)
+                    lastDelete = today
+                }
+
                 // get time until the next feed is pending, but wait at least the minimum delay time
                 var delayTimeMS = settings.minRefreshWaitTime * 1000L
                 try {
index cba05ea0cf40fed2abf1d7efe2e14ac46a564edf..ddf4f409701783ccfb8e72c33443ae9ac8053698 100644 (file)
@@ -482,7 +482,7 @@ object Database {
                                    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
+                    where max_age > 0 and age > max_age
                 )
             """.trimIndent()).use { stmt ->
                 stmt.setInt(1, defaultMaxItemAge)