diff --git a/kmp/feed-sync/runtime/src/commonMain/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/FeedSyncEngineImpl.kt b/kmp/feed-sync/runtime/src/commonMain/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/FeedSyncEngineImpl.kt index 78961652..86fadcfd 100644 --- a/kmp/feed-sync/runtime/src/commonMain/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/FeedSyncEngineImpl.kt +++ b/kmp/feed-sync/runtime/src/commonMain/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/FeedSyncEngineImpl.kt @@ -42,7 +42,7 @@ public class FeedSyncEngineImpl( .allFeedOrigins().asFlow().mapToList(dbDispatcher) .map { SyncRequest(forceRefresh = false, skipFeedSources = it.isNotEmpty()) } - private val syncDecisionMaker = SyncDecisionMaker( + private val syncRequestEvaluator = SyncRequestEvaluator( syncConfig = SyncConfig.Default, feedOriginEntityQueries = db.feedOriginEntityQueries, lastSyncMetadataQueries = db.lastSyncMetadataQueries, @@ -68,7 +68,7 @@ public class FeedSyncEngineImpl( } private suspend fun performSync(syncRequest: SyncRequest) = coroutineScope { - val (shouldSyncSources, shouldSyncItems) = syncDecisionMaker.decide(syncRequest) + val (shouldSyncSources, shouldSyncItems) = syncRequestEvaluator.evaluate(syncRequest) val feedSourcesDeferred = if (shouldSyncSources) { async { feedService.fetchFeedOrigins() } diff --git a/kmp/feed-sync/runtime/src/commonMain/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/SyncDecisionMaker.kt b/kmp/feed-sync/runtime/src/commonMain/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/SyncRequestEvaluator.kt similarity index 94% rename from kmp/feed-sync/runtime/src/commonMain/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/SyncDecisionMaker.kt rename to kmp/feed-sync/runtime/src/commonMain/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/SyncRequestEvaluator.kt index 3aa53623..38d43cf5 100644 --- a/kmp/feed-sync/runtime/src/commonMain/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/SyncDecisionMaker.kt +++ b/kmp/feed-sync/runtime/src/commonMain/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/SyncRequestEvaluator.kt @@ -6,13 +6,13 @@ import io.github.reactivecircus.kstreamlined.kmp.database.SyncResourceType import io.github.reactivecircus.kstreamlined.kmp.feed.sync.mapper.toSyncParams import kotlinx.datetime.Clock -internal class SyncDecisionMaker( +internal class SyncRequestEvaluator( private val syncConfig: SyncConfig, private val feedOriginEntityQueries: FeedOriginEntityQueries, private val lastSyncMetadataQueries: LastSyncMetadataQueries, private val clock: Clock, ) { - fun decide(syncRequest: SyncRequest): SyncDecision { + fun evaluate(syncRequest: SyncRequest): SyncDecision { return SyncDecision( shouldSyncFeedSources = !syncRequest.skipFeedSources && (syncRequest.forceRefresh || shouldSyncFeedSources()), diff --git a/kmp/feed-sync/runtime/src/commonTest/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/SyncDecisionMakerTest.kt b/kmp/feed-sync/runtime/src/commonTest/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/SyncRequestEvaluatorTest.kt similarity index 88% rename from kmp/feed-sync/runtime/src/commonTest/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/SyncDecisionMakerTest.kt rename to kmp/feed-sync/runtime/src/commonTest/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/SyncRequestEvaluatorTest.kt index b4e32d5b..480d5fa9 100644 --- a/kmp/feed-sync/runtime/src/commonTest/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/SyncDecisionMakerTest.kt +++ b/kmp/feed-sync/runtime/src/commonTest/kotlin/io/github/reactivecircus/kstreamlined/kmp/feed/sync/SyncRequestEvaluatorTest.kt @@ -8,7 +8,7 @@ import kotlin.test.assertFalse import kotlin.test.assertTrue import kotlin.time.Duration.Companion.seconds -class SyncDecisionMakerTest { +class SyncRequestEvaluatorTest { private val db = createInMemoryDatabase() @@ -16,7 +16,7 @@ class SyncDecisionMakerTest { private val fakeClock = FakeClock() - private val syncDecisionMaker = SyncDecisionMaker( + private val syncRequestEvaluator = SyncRequestEvaluator( syncConfig = syncConfig, feedOriginEntityQueries = db.feedOriginEntityQueries, lastSyncMetadataQueries = db.lastSyncMetadataQueries, @@ -26,14 +26,14 @@ class SyncDecisionMakerTest { @Test fun `should not sync feed sources when skipFeedSources is true`() { val syncRequest = SyncRequest(forceRefresh = true, skipFeedSources = true) - val result = syncDecisionMaker.decide(syncRequest) + val result = syncRequestEvaluator.evaluate(syncRequest) assertFalse(result.shouldSyncFeedSources) } @Test fun `should sync feed sources and feed items when forceRefresh is true`() { val syncRequest = SyncRequest(forceRefresh = true) - val result = syncDecisionMaker.decide(syncRequest) + val result = syncRequestEvaluator.evaluate(syncRequest) assertTrue(result.shouldSyncFeedSources) assertTrue(result.shouldSyncFeedItems) } @@ -41,7 +41,7 @@ class SyncDecisionMakerTest { @Test fun `should sync feed sources when no lastSyncMetadata exists`() { val syncRequest = SyncRequest(forceRefresh = false) - val result = syncDecisionMaker.decide(syncRequest) + val result = syncRequestEvaluator.evaluate(syncRequest) assertTrue(result.shouldSyncFeedSources) } @@ -56,7 +56,7 @@ class SyncDecisionMakerTest { fakeClock.currentTime += syncConfig.feedSourcesCacheMaxAge val syncRequest = SyncRequest(forceRefresh = false) - val result = syncDecisionMaker.decide(syncRequest) + val result = syncRequestEvaluator.evaluate(syncRequest) assertFalse(result.shouldSyncFeedSources) } @@ -71,14 +71,14 @@ class SyncDecisionMakerTest { fakeClock.currentTime += syncConfig.feedSourcesCacheMaxAge + 1.seconds val syncRequest = SyncRequest(forceRefresh = false) - val result = syncDecisionMaker.decide(syncRequest) + val result = syncRequestEvaluator.evaluate(syncRequest) assertTrue(result.shouldSyncFeedSources) } @Test fun `should sync feed items when no lastSyncMetadata exists`() { val syncRequest = SyncRequest(forceRefresh = false) - val result = syncDecisionMaker.decide(syncRequest) + val result = syncRequestEvaluator.evaluate(syncRequest) assertTrue(result.shouldSyncFeedItems) } @@ -106,7 +106,7 @@ class SyncDecisionMakerTest { fakeClock.currentTime += syncConfig.feedItemsCacheMaxAge val syncRequest = SyncRequest(forceRefresh = false) - val result = syncDecisionMaker.decide(syncRequest) + val result = syncRequestEvaluator.evaluate(syncRequest) assertFalse(result.shouldSyncFeedItems) } @@ -142,7 +142,7 @@ class SyncDecisionMakerTest { fakeClock.currentTime += syncConfig.feedItemsCacheMaxAge + 1.seconds val syncRequest = SyncRequest(forceRefresh = false) - val result = syncDecisionMaker.decide(syncRequest) + val result = syncRequestEvaluator.evaluate(syncRequest) assertTrue(result.shouldSyncFeedItems) } }