Have a collection fetching cache like we had for etesync v1.

This is there because we usually sync all of the adapters in tandem and
we were fetching all of the collections multiple times because of it.
pull/131/head
Tom Hacohen 4 years ago
parent b637f25f4a
commit 048acdf26c

@ -30,7 +30,6 @@ import com.etesync.syncadapter.*
import com.etesync.journalmanager.Crypto
import com.etesync.journalmanager.Exceptions
import com.etesync.journalmanager.JournalManager
import com.etesync.syncadapter.*
import com.etesync.syncadapter.log.Logger
import com.etesync.syncadapter.model.CollectionInfo
import com.etesync.syncadapter.model.JournalEntity
@ -247,6 +246,14 @@ abstract class SyncAdapterService : Service() {
val etebaseLocalCache = EtebaseLocalCache.getInstance(context, account.name)
synchronized(etebaseLocalCache) {
val cacheAge = 5 * 1000 // 5 seconds - it's just a hack for burst fetching
val now = System.currentTimeMillis()
val lastCollectionsFetch = collectionLastFetchMap[account.name] ?: 0
if (abs(now - lastCollectionsFetch) <= cacheAge) {
return@synchronized
}
val etebase = EtebaseLocalCache.getEtebase(context, httpClient.okHttpClient, settings)
val colMgr = etebase.collectionManager
var stoken = etebaseLocalCache.loadStoken()
@ -265,6 +272,7 @@ abstract class SyncAdapterService : Service() {
done = colList.isDone
etebaseLocalCache.saveStoken(stoken!!)
}
collectionLastFetchMap[account.name] = now
}
httpClient.close()
@ -308,5 +316,6 @@ abstract class SyncAdapterService : Service() {
companion object {
val journalFetcher = CachedJournalFetcher()
var collectionLastFetchMap = HashMap<String, Long>()
}
}

Loading…
Cancel
Save