Skip to content

Commit

Permalink
Add comments explaining backend sync and made variable names easier t…
Browse files Browse the repository at this point in the history
…o grok

Change-Id: I90cd7444de95efa20bf243a922a772f7849a23ec
  • Loading branch information
tunjid committed Apr 25, 2023
1 parent 022cd92 commit 337c940
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class OfflineFirstNewsRepository @Inject constructor(

// TODO: Make this more efficient, there is no need to retrieve populated
// news resources when all that's needed are the ids
val existingFollowedChangedNewsResourceIds = when {
hasOnBoarded -> newsResourceDao.getNewsResources(
val existingNewsResourceIdsThatHaveChanged = when {
hasOnboarded -> newsResourceDao.getNewsResources(
useFilterTopicIds = true,
filterTopicIds = followedTopicIds,
useFilterNewsIds = true,
Expand All @@ -94,6 +94,7 @@ class OfflineFirstNewsRepository @Inject constructor(
else -> emptySet()
}

// Obtain the news resources which have changed from the network and upsert them locally
changedIds.chunked(SYNC_BATCH_SIZE).forEach { chunkedIds ->
val networkNewsResources = network.getNewsResources(ids = chunkedIds)

Expand All @@ -118,12 +119,12 @@ class OfflineFirstNewsRepository @Inject constructor(
)
}

if (hasOnBoarded) {
if (hasOnboarded) {
val addedNewsResources = newsResourceDao.getNewsResources(
useFilterTopicIds = true,
filterTopicIds = followedTopicIds,
useFilterNewsIds = true,
filterNewsIds = changedIds.toSet() - existingFollowedChangedNewsResourceIds,
filterNewsIds = changedIds.toSet() - existingNewsResourceIdsThatHaveChanged,
)
.first()
.map(PopulatedNewsResource::asExternalModel)
Expand Down

0 comments on commit 337c940

Please sign in to comment.