From 048acdf26c772ce0e4230f9d3dfa8cb9169e51f1 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 7 Sep 2020 18:26:18 +0300 Subject: [PATCH] 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. --- .../syncadapter/syncadapter/SyncAdapterService.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncAdapterService.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncAdapterService.kt index 897b3171..743deb75 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncAdapterService.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncAdapterService.kt @@ -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() } }