diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt index f1ff13198cf139101d592e32d523d107db10d0db..d4e6839294fd214dc5e94d2e570f70e75fad4e63 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt @@ -20,7 +20,6 @@ import android.content.Context import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.stringPreferencesKey import androidx.datastore.preferences.preferencesDataStore -import com.fsck.k9.Account import com.fsck.k9.controller.MessageReference import com.google.gson.Gson import com.google.gson.TypeAdapter @@ -55,7 +54,7 @@ class EmailCache constructor(private val context: Context, private val gson: Gso } suspend fun saveLatestMails(mailList: List) { - if (isCacheShown) return + if (mailList.size < MAX_CACHE_SIZE || isCacheShown) return isCacheShown = true val cachedMailsWithLatest = getLatestMails(mailList) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt index 3644e3fa3c626f355d783432db182a4e21ce5fe5..77cb52c9c9a87cf3eaa1299f18cb08391a1a6377 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt @@ -25,15 +25,21 @@ class MessageListLiveData( private fun loadMessageListAsync() { coroutineScope.launch(Dispatchers.Main) { - emailCache.getCachedMails()?.let { + val cachedMessages = withContext(Dispatchers.IO) { + emailCache.getCachedMails() + } + + cachedMessages?.let { value = MessageListInfo(it, true) } val messageList = withContext(Dispatchers.IO) { - messageListLoader.getMessageList(config) + val result = messageListLoader.getMessageList(config) + emailCache.saveLatestMails(result.messageListItems) + result } + value = messageList - emailCache.saveLatestMails(messageList.messageListItems) } }