diff --git a/Wino.Services/MailService.cs b/Wino.Services/MailService.cs index 5140e28f..9da2f03d 100644 --- a/Wino.Services/MailService.cs +++ b/Wino.Services/MailService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -229,9 +230,9 @@ public class MailService : BaseDatabaseService, IMailService mails = await Connection.QueryAsync(query); } - Dictionary folderCache = []; - Dictionary accountCache = []; - Dictionary contactCache = []; + ConcurrentDictionary folderCache = new(); + ConcurrentDictionary accountCache = new(); + ConcurrentDictionary contactCache = new(); // Populate Folder Assignment for each single mail, to be able later group by "MailAccountId". // This is needed to execute threading strategy by account type. @@ -321,7 +322,7 @@ public class MailService : BaseDatabaseService, IMailService /// This method should used for operations with multiple mailItems. Don't use this for single mail items. /// Called method should provide own instances for caches. /// - private async Task LoadAssignedPropertiesWithCacheAsync(MailCopy mail, Dictionary folderCache, Dictionary accountCache, Dictionary contactCache) + private async Task LoadAssignedPropertiesWithCacheAsync(MailCopy mail, ConcurrentDictionary folderCache, ConcurrentDictionary accountCache, ConcurrentDictionary contactCache) { if (mail is MailCopy mailCopy) { @@ -1168,9 +1169,9 @@ public class MailService : BaseDatabaseService, IMailService var mailCopies = await Connection.QueryAsync(query); if (mailCopies?.Count == 0) return []; - Dictionary folderCache = []; - Dictionary accountCache = []; - Dictionary contactCache = []; + ConcurrentDictionary folderCache = new(); + ConcurrentDictionary accountCache = new(); + ConcurrentDictionary contactCache = new(); foreach (var mail in mailCopies) {