fetch cards list then content for first 20 updated items

This commit is contained in:
Satindar Dhillon
2023-01-18 08:59:08 -08:00
parent bb1efac336
commit f352f2a3de
2 changed files with 15 additions and 9 deletions

View File

@ -4,7 +4,7 @@ import android.util.Log
import app.omnivore.omnivore.networking.*
import app.omnivore.omnivore.persistence.entities.*
suspend fun DataService.sync(since: String, cursor: String?, limit: Int = 15): SavedItemSyncResult {
suspend fun DataService.sync(since: String, cursor: String?, limit: Int = 20): SavedItemSyncResult {
val syncResult = networker.savedItemUpdates(cursor = cursor, limit = limit, since = since) ?: return SavedItemSyncResult.errorResult
val savedItems = syncResult.items.map {

View File

@ -81,23 +81,29 @@ class LibraryViewModel @Inject constructor(
}
}
private suspend fun performItemSync(cursor: String?, since: String, count: Int, startTime: String) {
private suspend fun performItemSync(cursor: String?, since: String, count: Int, startTime: String, fetchContentSlugs: List<String> = listOf()) {
dataService.syncOfflineItemsWithServerIfNeeded()
val result = dataService.sync(since = since, cursor = cursor)
// TODO: Defer this until later? /fix - this results in a 429 server error
// for (slug in result.savedItemSlugs) {
// dataService.syncSavedItemContent(slug)
// }
val totalCount = count + result.count
Log.d("sync", "fetched ${result.count} items")
if (totalCount < 180 && !result.hasError && result.hasMoreItems && result.cursor != null) {
performItemSync(cursor = result.cursor, since = since, count = totalCount, startTime = startTime)
if (!result.hasError && result.hasMoreItems && result.cursor != null) {
performItemSync(
cursor = result.cursor,
since = since,
count = totalCount,
startTime = startTime,
fetchContentSlugs = fetchContentSlugs.ifEmpty { result.savedItemSlugs }
)
} else {
datastoreRepo.putString(DatastoreKeys.libraryLastSyncTimestamp, startTime)
for (slug in result.savedItemSlugs) {
dataService.syncSavedItemContent(slug)
}
}
}