From 5cacc77025f6fad5f785df52a6d5674eb88eaf18 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Mon, 22 Sep 2025 18:20:33 +0200 Subject: [PATCH] add automatic item cleanup --- .../src/main/kotlin/de/unixwork/rssreader/App.kt | 11 +++++++++++ .../src/main/kotlin/de/unixwork/rssreader/Database.kt | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt index 2e18ec7..ef16805 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt @@ -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 { 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 cba05ea..ddf4f40 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -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) -- 2.47.3