From 51ddd794e13187fd6f07c8ae45ff71e56f34d9d6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 30 Jul 2024 09:11:43 +0530 Subject: [PATCH 1/3] Update dependency com.google.devtools.ksp to v2.0.0-1.0.24 (#679) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7d8b1c159..e7f6ad636 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -29,7 +29,7 @@ coil = "3.0.0-alpha09" spotless = "6.25.0" ktfmt = "0.44" kotlininject = "0.7.1" -ksp = "2.0.0-1.0.23" +ksp = "2.0.0-1.0.24" material_color_utilities = "1.0.0-alpha01" ksoup = "0.1.2" sqliteAndroid = "3.45.0" From 42a3b4507f94c32ae6a4b74063713a0d5b8af891 Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Tue, 30 Jul 2024 17:16:37 +0530 Subject: [PATCH 2/3] Use `TransactionRunner` for running DB queries in a transaction --- .../sasikanth/rss/reader/data/repository/RssRepository.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/data/src/commonMain/kotlin/dev/sasikanth/rss/reader/data/repository/RssRepository.kt b/core/data/src/commonMain/kotlin/dev/sasikanth/rss/reader/data/repository/RssRepository.kt index 248bd9ca7..8821c9596 100644 --- a/core/data/src/commonMain/kotlin/dev/sasikanth/rss/reader/data/repository/RssRepository.kt +++ b/core/data/src/commonMain/kotlin/dev/sasikanth/rss/reader/data/repository/RssRepository.kt @@ -94,7 +94,7 @@ class RssRepository( id = feedId ) - postQueries.transaction { + transactionRunner.invoke { val feedLastCleanUpAtEpochMilli = feedLastCleanUpAt?.toEpochMilliseconds() ?: Instant.DISTANT_PAST.toEpochMilliseconds() @@ -486,7 +486,7 @@ class RssRepository( suspend fun updateFeedsLastCleanUpAt(feedIds: List) { withContext(ioDispatcher) { - feedQueries.transaction { + transactionRunner.invoke { feedIds.forEach { feedId -> feedQueries.updateLastCleanUpAt(lastCleanUpAt = Clock.System.now(), id = feedId) } @@ -503,7 +503,7 @@ class RssRepository( postsAfter: Instant = Instant.DISTANT_PAST ) { withContext(ioDispatcher) { - postQueries.transaction { + transactionRunner.invoke { feedIds.forEach { feedId -> postQueries.markPostsAsRead(sourceId = feedId, after = postsAfter) } @@ -868,7 +868,7 @@ class RssRepository( suspend fun updatedSourcePinnedPosition(sources: List) { withContext(ioDispatcher) { - feedQueries.transaction { + transactionRunner.invoke { sources.forEachIndexed { index, source -> feedQueries.updatedPinnedPosition(index.toDouble(), source.id) feedGroupQueries.updatedPinnedPosition(index.toDouble(), source.id) From b8b94b88337c8d50f10f4deac1c0e1dbcb18f7a2 Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Tue, 30 Jul 2024 17:45:13 +0530 Subject: [PATCH 3/3] Remove nested conditionals from `FeedFetcher` --- .../core/network/fetcher/FeedFetcher.kt | 72 +++++++++---------- .../reader/core/network/parser/FeedParser.kt | 2 - 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/fetcher/FeedFetcher.kt b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/fetcher/FeedFetcher.kt index b484d478c..8e9caf19c 100644 --- a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/fetcher/FeedFetcher.kt +++ b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/fetcher/FeedFetcher.kt @@ -53,34 +53,34 @@ class FeedFetcher(private val httpClient: HttpClient, private val feedParser: Fe transformUrl: Boolean, redirectCount: Int, ): FeedFetchResult { - return if (redirectCount < MAX_REDIRECTS_ALLOWED) { - try { - // We are mainly doing this check to avoid creating duplicates while refreshing feeds - // after the app update - val transformedUrl = transformUrl(url, transformUrl) - val response = httpClient.get(transformedUrl.toString()) - - when (response.status) { - HttpStatusCode.OK -> { - parseContent(response, transformedUrl.toString(), redirectCount) - } - HttpStatusCode.MultipleChoices, - HttpStatusCode.MovedPermanently, - HttpStatusCode.Found, - HttpStatusCode.SeeOther, - HttpStatusCode.TemporaryRedirect, - HttpStatusCode.PermanentRedirect -> { - handleHttpRedirect(response, transformedUrl.toString(), redirectCount) - } - else -> { - FeedFetchResult.HttpStatusError(statusCode = response.status) - } + if (redirectCount >= MAX_REDIRECTS_ALLOWED) { + return FeedFetchResult.TooManyRedirects + } + + return try { + // We are mainly doing this to avoid creating duplicates while refreshing feeds + // after the app update + val transformedUrl = transformUrl(url, transformUrl) + val response = httpClient.get(transformedUrl.toString()) + + when (response.status) { + HttpStatusCode.OK -> { + parseContent(response, transformedUrl.toString(), redirectCount) + } + HttpStatusCode.MultipleChoices, + HttpStatusCode.MovedPermanently, + HttpStatusCode.Found, + HttpStatusCode.SeeOther, + HttpStatusCode.TemporaryRedirect, + HttpStatusCode.PermanentRedirect -> { + handleHttpRedirect(response, transformedUrl.toString(), redirectCount) + } + else -> { + FeedFetchResult.HttpStatusError(statusCode = response.status) } - } catch (e: Exception) { - FeedFetchResult.Error(e) } - } else { - FeedFetchResult.TooManyRedirects + } catch (e: Exception) { + FeedFetchResult.Error(e) } } @@ -89,23 +89,23 @@ class FeedFetcher(private val httpClient: HttpClient, private val feedParser: Fe url: String, redirectCount: Int ): FeedFetchResult { - return if (response.contentType()?.withoutParameters() == ContentType.Text.Html) { - val feedUrl = fetchFeedLinkFromHtmlIfExists(response.bodyAsText(), url) - - if (feedUrl != url && !feedUrl.isNullOrBlank()) { - fetch(url = feedUrl, transformUrl = false, redirectCount = redirectCount + 1) - } else { - throw UnsupportedOperationException() - } - } else { + if (response.contentType()?.withoutParameters() != ContentType.Text.Html) { val content = response.bodyAsChannel() val responseCharset = response.contentType()?.parameter("charset") val charset = Charset.forName(responseCharset ?: Charsets.UTF8.name) val feedPayload = feedParser.parse(feedUrl = url, content = content, charset = charset) - FeedFetchResult.Success(feedPayload) + return FeedFetchResult.Success(feedPayload) } + + val feedUrl = fetchFeedLinkFromHtmlIfExists(response.bodyAsText(), url) + + if (feedUrl != url && !feedUrl.isNullOrBlank()) { + return fetch(url = feedUrl, transformUrl = false, redirectCount = redirectCount + 1) + } + + throw UnsupportedOperationException() } private suspend fun handleHttpRedirect( diff --git a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/FeedParser.kt b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/FeedParser.kt index 852648864..ffda49fc6 100644 --- a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/FeedParser.kt +++ b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/FeedParser.kt @@ -17,7 +17,6 @@ package dev.sasikanth.rss.reader.core.network.parser import co.touchlab.kermit.Logger import dev.sasikanth.rss.reader.core.model.remote.FeedPayload -import dev.sasikanth.rss.reader.di.scopes.AppScope import dev.sasikanth.rss.reader.exceptions.XmlParsingError import dev.sasikanth.rss.reader.util.DispatchersProvider import io.ktor.http.URLBuilder @@ -35,7 +34,6 @@ import org.kobjects.ktxml.api.XmlPullParserException import org.kobjects.ktxml.mini.MiniXmlPullParser @Inject -@AppScope class FeedParser(private val dispatchersProvider: DispatchersProvider) { suspend fun parse(