Only fetch changed collections

pull/1244/head
Alex Baker 5 years ago
parent f1a26ec1f3
commit 113fe85376

@ -29,10 +29,15 @@ class EtebaseClient(
@Throws(Exceptions.HttpException::class) @Throws(Exceptions.HttpException::class)
suspend fun getCollections(): List<Collection> { suspend fun getCollections(): List<Collection> {
val collectionManager = etebase.collectionManager val collectionManager = etebase.collectionManager
var stoken: String? = cache.loadStoken()
do { do {
val response = withContext(Dispatchers.IO) { val response = withContext(Dispatchers.IO) {
collectionManager.list(TYPE_TASKS) collectionManager.list(
TYPE_TASKS,
FetchOptions().stoken(stoken).limit(MAX_FETCH)
)
} }
stoken = response.stoken
response.data.forEach { response.data.forEach {
cache.collectionSet(collectionManager, it) cache.collectionSet(collectionManager, it)
} }
@ -40,6 +45,7 @@ class EtebaseClient(
cache.collectionUnset(collectionManager, it) cache.collectionUnset(collectionManager, it)
} }
} while (!response.isDone) } while (!response.isDone)
stoken?.let { cache.saveStoken(it) }
return cache.collectionList(collectionManager) return cache.collectionList(collectionManager)
} }

@ -19,6 +19,16 @@ class EtebaseLocalCache private constructor(context: Context, username: String)
} }
} }
suspend fun saveStoken(stoken: String) {
withContext(Dispatchers.IO) {
fsCache.saveStoken(stoken)
}
}
suspend fun loadStoken(): String? = withContext(Dispatchers.IO) {
fsCache.loadStoken()
}
suspend fun collectionList(colMgr: CollectionManager): List<Collection> = suspend fun collectionList(colMgr: CollectionManager): List<Collection> =
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
fsCache._unstable_collectionList(colMgr).filter { !it.isDeleted } fsCache._unstable_collectionList(colMgr).filter { !it.isDeleted }

Loading…
Cancel
Save