Rename EmailProviderCache to MessageListCache

This commit is contained in:
cketti 2022-08-31 17:09:56 +02:00
parent 7ea928bba5
commit cfa01261ae
6 changed files with 32 additions and 41 deletions

View file

@ -39,7 +39,6 @@ import com.fsck.k9.backend.api.Backend;
import com.fsck.k9.backend.api.BuildConfig;
import com.fsck.k9.backend.api.SyncConfig;
import com.fsck.k9.backend.api.SyncListener;
import com.fsck.k9.cache.EmailProviderCache;
import com.fsck.k9.controller.ControllerExtension.ControllerInternals;
import com.fsck.k9.controller.MessagingControllerCommands.PendingAppend;
import com.fsck.k9.controller.MessagingControllerCommands.PendingCommand;
@ -71,6 +70,7 @@ import com.fsck.k9.mailstore.LocalFolder;
import com.fsck.k9.mailstore.LocalMessage;
import com.fsck.k9.mailstore.LocalStore;
import com.fsck.k9.mailstore.LocalStoreProvider;
import com.fsck.k9.mailstore.MessageListCache;
import com.fsck.k9.mailstore.MessageStore;
import com.fsck.k9.mailstore.MessageStoreManager;
import com.fsck.k9.mailstore.OutboxState;
@ -322,12 +322,12 @@ public class MessagingController {
private void suppressMessages(Account account, List<LocalMessage> messages) {
EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid());
MessageListCache cache = MessageListCache.getCache(account.getUuid());
cache.hideMessages(messages);
}
private void unsuppressMessages(Account account, List<LocalMessage> messages) {
EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid());
MessageListCache cache = MessageListCache.getCache(account.getUuid());
cache.unhideMessages(messages);
}
@ -335,14 +335,14 @@ public class MessagingController {
long messageId = message.getDatabaseId();
long folderId = message.getFolder().getDatabaseId();
EmailProviderCache cache = EmailProviderCache.getCache(message.getFolder().getAccountUuid());
MessageListCache cache = MessageListCache.getCache(message.getFolder().getAccountUuid());
return cache.isMessageHidden(messageId, folderId);
}
private void setFlagInCache(final Account account, final List<Long> messageIds,
final Flag flag, final boolean newState) {
EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid());
MessageListCache cache = MessageListCache.getCache(account.getUuid());
String columnName = LocalStore.getColumnNameForFlag(flag);
String value = Integer.toString((newState) ? 1 : 0);
cache.setValueForMessages(messageIds, columnName, value);
@ -351,7 +351,7 @@ public class MessagingController {
private void removeFlagFromCache(final Account account, final List<Long> messageIds,
final Flag flag) {
EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid());
MessageListCache cache = MessageListCache.getCache(account.getUuid());
String columnName = LocalStore.getColumnNameForFlag(flag);
cache.removeValueForMessages(messageIds, columnName);
}
@ -359,7 +359,7 @@ public class MessagingController {
private void setFlagForThreadsInCache(final Account account, final List<Long> threadRootIds,
final Flag flag, final boolean newState) {
EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid());
MessageListCache cache = MessageListCache.getCache(account.getUuid());
String columnName = LocalStore.getColumnNameForFlag(flag);
String value = Integer.toString((newState) ? 1 : 0);
cache.setValueForThreads(threadRootIds, columnName, value);
@ -368,7 +368,7 @@ public class MessagingController {
private void removeFlagForThreadsFromCache(final Account account, final List<Long> messageIds,
final Flag flag) {
EmailProviderCache cache = EmailProviderCache.getCache(account.getUuid());
MessageListCache cache = MessageListCache.getCache(account.getUuid());
String columnName = LocalStore.getColumnNameForFlag(flag);
cache.removeValueForThreads(messageIds, columnName);
}

View file

@ -1,9 +1,7 @@
package com.fsck.k9.mailstore
import com.fsck.k9.cache.EmailProviderCache
internal class CacheAwareMessageMapper<T>(
private val cache: EmailProviderCache,
private val cache: MessageListCache,
private val messageMapper: MessageMapper<T>
) : MessageMapper<T?> {
override fun map(message: MessageDetailsAccessor): T? {
@ -20,7 +18,7 @@ internal class CacheAwareMessageMapper<T>(
}
private class CacheAwareMessageDetailsAccessor(
private val cache: EmailProviderCache,
private val cache: MessageListCache,
private val message: MessageDetailsAccessor
) : MessageDetailsAccessor by message {
override val isRead: Boolean

View file

@ -1,8 +1,6 @@
package com.fsck.k9.cache
package com.fsck.k9.mailstore
import com.fsck.k9.DI
import com.fsck.k9.mailstore.LocalMessage
import com.fsck.k9.mailstore.MessageListRepository
import kotlin.collections.set
typealias MessageId = Long
@ -15,7 +13,7 @@ typealias AccountUuid = String
/**
* Cache to bridge the time needed to write (user-initiated) changes to the database.
*/
class EmailProviderCache private constructor(private val accountUuid: String) {
class MessageListCache private constructor(private val accountUuid: String) {
private val messageCache = mutableMapOf<MessageId, MutableMap<ColumnName, ColumnValue>>()
private val threadCache = mutableMapOf<ThreadId, MutableMap<ColumnName, ColumnValue>>()
private val hiddenMessageCache = mutableMapOf<MessageId, FolderId>()
@ -122,12 +120,12 @@ class EmailProviderCache private constructor(private val accountUuid: String) {
}
companion object {
private val instances = mutableMapOf<AccountUuid, EmailProviderCache>()
private val instances = mutableMapOf<AccountUuid, MessageListCache>()
@JvmStatic
@Synchronized
fun getCache(accountUuid: String): EmailProviderCache {
return instances.getOrPut(accountUuid) { EmailProviderCache(accountUuid) }
fun getCache(accountUuid: String): MessageListCache {
return instances.getOrPut(accountUuid) { MessageListCache(accountUuid) }
}
}
}

View file

@ -1,6 +1,5 @@
package com.fsck.k9.mailstore
import com.fsck.k9.cache.EmailProviderCache
import java.util.concurrent.CopyOnWriteArraySet
class MessageListRepository(
@ -26,7 +25,7 @@ class MessageListRepository(
}
/**
* Retrieve list of messages from [MessageStore] but override values with data from [EmailProviderCache].
* Retrieve list of messages from [MessageStore] but override values with data from [MessageListCache].
*/
fun <T> getMessages(
accountUuid: String,
@ -36,14 +35,14 @@ class MessageListRepository(
messageMapper: MessageMapper<T>
): List<T> {
val messageStore = messageStoreManager.getMessageStore(accountUuid)
val cache = EmailProviderCache.getCache(accountUuid)
val cache = MessageListCache.getCache(accountUuid)
val mapper = CacheAwareMessageMapper(cache, messageMapper)
return messageStore.getMessages(selection, selectionArgs, sortOrder, mapper)
}
/**
* Retrieve threaded list of messages from [MessageStore] but override values with data from [EmailProviderCache].
* Retrieve threaded list of messages from [MessageStore] but override values with data from [MessageListCache].
*/
fun <T> getThreadedMessages(
accountUuid: String,
@ -53,14 +52,14 @@ class MessageListRepository(
messageMapper: MessageMapper<T>
): List<T> {
val messageStore = messageStoreManager.getMessageStore(accountUuid)
val cache = EmailProviderCache.getCache(accountUuid)
val cache = MessageListCache.getCache(accountUuid)
val mapper = CacheAwareMessageMapper(cache, messageMapper)
return messageStore.getThreadedMessages(selection, selectionArgs, sortOrder, mapper)
}
/**
* Retrieve list of messages in a thread from [MessageStore] but override values with data from [EmailProviderCache].
* Retrieve list of messages in a thread from [MessageStore] but override values with data from [MessageListCache].
*/
fun <T> getThread(
accountUuid: String,
@ -69,7 +68,7 @@ class MessageListRepository(
messageMapper: MessageMapper<T>
): List<T> {
val messageStore = messageStoreManager.getMessageStore(accountUuid)
val cache = EmailProviderCache.getCache(accountUuid)
val cache = MessageListCache.getCache(accountUuid)
val mapper = CacheAwareMessageMapper(cache, messageMapper)
return messageStore.getThread(threadId, sortOrder, mapper)

View file

@ -1,8 +1,5 @@
package com.fsck.k9.cache
package com.fsck.k9.mailstore
import com.fsck.k9.mailstore.LocalFolder
import com.fsck.k9.mailstore.LocalMessage
import com.fsck.k9.mailstore.MessageListRepository
import com.google.common.truth.Truth.assertThat
import java.util.UUID
import org.junit.After
@ -17,7 +14,7 @@ import org.mockito.kotlin.mock
private const val MESSAGE_ID = 1L
private const val FOLDER_ID = 2L
class EmailProviderCacheTest {
class MessageListCacheTest {
private val localFolder = mock<LocalFolder> {
on { databaseId } doReturn FOLDER_ID
}
@ -27,7 +24,7 @@ class EmailProviderCacheTest {
on { folder } doReturn localFolder
}
private val cache = EmailProviderCache.getCache(UUID.randomUUID().toString())
private val cache = MessageListCache.getCache(UUID.randomUUID().toString())
@Before
fun setUp() {
@ -47,18 +44,18 @@ class EmailProviderCacheTest {
@Test
fun `getCache() returns different cache for each UUID`() {
val cache = EmailProviderCache.getCache("u001")
val cache = MessageListCache.getCache("u001")
val cache2 = EmailProviderCache.getCache("u002")
val cache2 = MessageListCache.getCache("u002")
assertThat(cache2).isNotSameInstanceAs(cache)
}
@Test
fun `getCache() returns same cache for the same UUID`() {
val cache = EmailProviderCache.getCache("u001")
val cache = MessageListCache.getCache("u001")
val cache2 = EmailProviderCache.getCache("u001")
val cache2 = MessageListCache.getCache("u001")
assertThat(cache2).isSameInstanceAs(cache)
}

View file

@ -1,6 +1,5 @@
package com.fsck.k9.mailstore
import com.fsck.k9.cache.EmailProviderCache
import com.fsck.k9.mail.Address
import com.fsck.k9.message.extractors.PreviewResult
import com.google.common.truth.Truth.assertThat
@ -106,7 +105,7 @@ class MessageListRepositoryTest {
isForwarded = true
)
)
EmailProviderCache.getCache(accountUuid).apply {
MessageListCache.getCache(accountUuid).apply {
setValueForMessages(listOf(MESSAGE_ID), "read", "1")
setValueForThreads(listOf(THREAD_ROOT), "flagged", "0")
}
@ -179,7 +178,7 @@ class MessageListRepositoryTest {
isForwarded = true
)
)
EmailProviderCache.getCache(accountUuid).apply {
MessageListCache.getCache(accountUuid).apply {
setValueForMessages(listOf(MESSAGE_ID), "read", "1")
setValueForThreads(listOf(THREAD_ROOT), "flagged", "0")
}
@ -277,7 +276,7 @@ class MessageListRepositoryTest {
isForwarded = false
)
)
EmailProviderCache.getCache(accountUuid).apply {
MessageListCache.getCache(accountUuid).apply {
setValueForMessages(listOf(MESSAGE_ID), "read", "1")
setValueForThreads(listOf(THREAD_ROOT), "flagged", "0")
}
@ -407,7 +406,7 @@ class MessageListRepositoryTest {
@Suppress("SameParameterValue")
private fun hideMessage(messageId: Long, folderId: Long) {
val cache = EmailProviderCache.getCache(accountUuid)
val cache = MessageListCache.getCache(accountUuid)
val localFolder = mock<LocalFolder> {
on { databaseId } doReturn folderId