From 5ef011c2aa4ae536ae61d32f54b46acd62be791e Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sun, 7 Sep 2025 12:42:10 +0200 Subject: [PATCH] improve SyncJob: fetch feed list in IO thread --- .../src/main/kotlin/de/unixwork/rssreader/App.kt | 2 +- .../src/main/kotlin/de/unixwork/rssreader/SyncJob.kt | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) 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 c1a3bac..33eeec1 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt @@ -14,7 +14,7 @@ class App : Application { fun initToolbar() { toolbarItem(name = "reload", icon = "view-refresh") { event -> val window = event.windowData as MainWindow - SyncJob().sync() { + SyncJob({ Database.getAllFeeds()}).sync() { window.sourceList.invalidateCache() window.sourceList.reloadStatus() window.feedList.reloadCurrentFeed() diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/SyncJob.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/SyncJob.kt index 70d19e9..f205f7d 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/SyncJob.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/SyncJob.kt @@ -14,16 +14,14 @@ import java.net.http.HttpClient import java.net.http.HttpRequest import java.net.http.HttpResponse -class SyncJob { - val feeds: List +class SyncJob(feeds: () -> List) { + val getFeeds: () -> List = feeds var completionContext = ToolkitDispatcher - init { - feeds = Database.getAllFeeds() - } - fun sync(completion: () -> Unit = {}) { GlobalScope.launch(Dispatchers.IO) { + val feeds = getFeeds() + val client = HttpClient.newBuilder().build() val jobs = feeds.map { feed -> async { @@ -81,11 +79,9 @@ class SyncJob { } Database.addItems(items) Database.updateFeedDate(feed) - syndFeed } } catch (e: Exception) { println("Failed to fetch ${feed.uri}: ${e.message}") - null } } } -- 2.47.3