Skip to content

Commit

Permalink
fix(mail): use pool to lower memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Oct 12, 2021
1 parent ddfbb98 commit cae51dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
21 changes: 12 additions & 9 deletions SoObjects/Mailer/SOGoMailFolder.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
02111-1307, USA.
*/

#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSFileHandle.h>

Expand Down Expand Up @@ -2302,14 +2303,16 @@ - (NSArray *) syncTokenFieldsWithProperties: (NSDictionary *) theProperties
threaded: (BOOL) isThreaded
{
EOQualifier *searchQualifier;
NSAutoreleasePool *pool;
NSMutableArray *allTokens;
NSArray *a, *uids;
NSDictionary *d;
id fetchResults;
id fetchResults, sortedResults;

int highestmodseq = 0, i;

allTokens = [NSMutableArray array];
pool = [[NSAutoreleasePool alloc] init];

if (![theSyncToken isEqualToString: @"-1"])
{
Expand All @@ -2319,7 +2322,6 @@ - (NSArray *) syncTokenFieldsWithProperties: (NSDictionary *) theProperties

// We first make sure QRESYNC is enabled
[[self imap4Connection] enableExtensions: [NSArray arrayWithObject: @"QRESYNC"]];


// We fetch new messages and modified messages
if (highestmodseq)
Expand Down Expand Up @@ -2367,25 +2369,26 @@ - (NSArray *) syncTokenFieldsWithProperties: (NSDictionary *) theProperties
{
/* NOTE: we sort items manually because Cyrus does not properly sort
entries with a MODSEQ of 0 */
fetchResults = [fetchResults sortedArrayUsingFunction: _compareFetchResultsByMODSEQ
sortedResults = [fetchResults sortedArrayUsingFunction: _compareFetchResultsByMODSEQ
context: NULL];
}
else
{
fetchResults = [fetchResults sortedArrayUsingFunction: (int(*)(id, id, void*))_compareFetchResultsByUID
sortedResults = [fetchResults sortedArrayUsingFunction: (int(*)(id, id, void*))_compareFetchResultsByUID
context: uids];
}

for (i = 0; i < [fetchResults count]; i++)
{
if ([[[fetchResults objectAtIndex: i] objectForKey: @"flags"] containsObject: @"deleted"] && initialLoadInProgress)
for (i = 0; i < [sortedResults count]; i++)
{
if ([[[sortedResults objectAtIndex: i] objectForKey: @"flags"] containsObject: @"deleted"] && initialLoadInProgress)
continue;

d = [NSDictionary dictionaryWithObject: ([[[fetchResults objectAtIndex: i] objectForKey: @"flags"] containsObject: @"deleted"]) ? [NSNull null] : [[fetchResults objectAtIndex: i] objectForKey: @"modseq"]
forKey: [[[fetchResults objectAtIndex: i] objectForKey: @"uid"] stringValue]];
d = [NSDictionary dictionaryWithObject: ([[[sortedResults objectAtIndex: i] objectForKey: @"flags"] containsObject: @"deleted"]) ? [NSNull null] : [[sortedResults objectAtIndex: i] objectForKey: @"modseq"]
forKey: [[[sortedResults objectAtIndex: i] objectForKey: @"uid"] stringValue]];
[allTokens addObject: d];
}

[pool release];

// We fetch deleted ones
if (highestmodseq == 0)
Expand Down
13 changes: 12 additions & 1 deletion UI/MailerUI/UIxMailListActions.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2006-2015 Inverse inc.
Copyright (C) 2006-2021 Inverse inc.
This file is part of SOGo
Expand All @@ -26,6 +26,7 @@
object.
*/

#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSCalendarDate.h>
#import <Foundation/NSCharacterSet.h>
#import <Foundation/NSTimeZone.h>
Expand Down Expand Up @@ -867,6 +868,7 @@ - (NSArray *) getHeadersForUIDs: (NSArray *) uids
inFolder: (SOGoMailFolder *) mailFolder
{
UIxEnvelopeAddressFormatter *addressFormatter;
NSAutoreleasePool *pool;
NSMutableArray *headers, *msg, *tags;
NSEnumerator *msgsList;
NSArray *to, *from;
Expand All @@ -890,6 +892,8 @@ - (NSArray *) getHeadersForUIDs: (NSArray *) uids

msg = [NSMutableArray arrayWithObjects: @"To", @"hasAttachment", @"isFlagged", @"Subject", @"From", @"isRead", @"Priority", @"RelativeDate", @"Size", @"Flags", @"uid", @"isAnswered", @"isForwarded", nil];
[headers addObject: msg];
count = 0;
pool = [[NSAutoreleasePool alloc] init];
while (message)
{
// We must check for "umimportant" untagged responses.
Expand Down Expand Up @@ -976,6 +980,13 @@ - (NSArray *) getHeadersForUIDs: (NSArray *) uids
[msg addObject: [NSNumber numberWithBool: [self isMessageForwarded]]];

[self setMessage: [msgsList nextObject]];

count++;
if (count % 10 == 0)
{
[pool release];
pool = [[NSAutoreleasePool alloc] init];
}
}
}

Expand Down

0 comments on commit cae51dc

Please sign in to comment.