Skip to content

Commit

Permalink
fix(mail): improve performance of listing all mailboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Jun 4, 2021
1 parent 9cf67d0 commit 54548c5
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions SoObjects/Mailer/SOGoMailAccount.m
Expand Up @@ -429,15 +429,18 @@ - (NSArray *) allFolderPaths: (SOGoMailListingMode) theListingMode
- (NSString *) _folderType: (NSString *) folderName
flags: (NSMutableArray *) flags
{
static NSDictionary *metadata = nil;
NSString *folderType, *key;
NSDictionary *metadata;
SOGoUserDefaults *ud;

ud = [[context activeUser] userDefaults];

metadata = [[[self imap4Connection] allFoldersMetadataForURL: [self imap4URL]
onlySubscribedFolders: [ud mailShowSubscribedFoldersOnly]]
objectForKey: @"list"];
if (!metadata)
{
ud = [[context activeUser] userDefaults];
metadata = [[[self imap4Connection] allFoldersMetadataForURL: [self imap4URL]
onlySubscribedFolders: [ud mailShowSubscribedFoldersOnly]]
objectForKey: @"list"];
[metadata retain];
}

key = [NSString stringWithFormat: @"/%@", folderName];
[flags addObjectsFromArray: [metadata objectForKey: key]];
Expand Down Expand Up @@ -488,6 +491,7 @@ - (NSMutableDictionary *) _insertFolder: (NSString *) folderPath
parentIsOtherUsersFolder = NO;
pathComponents = [folderPath pathComponents];
count = [pathComponents count];
currentPath = @"";

// Make sure all ancestors exist.
// The variable folderPath is something like '/INBOX/Junk' so pathComponents becomes ('/', 'INBOX', 'Junk').
Expand All @@ -496,7 +500,10 @@ - (NSMutableDictionary *) _insertFolder: (NSString *) folderPath
{
last = ((count - i) == 1);
folder = nil;
currentPath = [[[pathComponents subarrayWithRange: NSMakeRange(0,i+1)] componentsJoinedByString: @"/"] substringFromIndex: 2];
if ([currentPath length])
currentPath = [NSString stringWithFormat: @"%@/%@", currentPath, [pathComponents objectAtIndex: i]];
else
currentPath = [pathComponents objectAtIndex: i];

// Search for the current path in the children of the parent folder.
// For the first iteration, take the parent folder passed as argument.
Expand Down

0 comments on commit 54548c5

Please sign in to comment.