From: helge Date: Fri, 8 Jul 2005 08:46:10 +0000 (+0000) Subject: added caching of ACL entries X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=561c3291912612d97a974f30c7e33bd136935d11;p=scalable-opengroupware.org added caching of ACL entries git-svn-id: http://svn.opengroupware.org/SOGo/trunk@694 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 43def422..438b09ce 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,3 +1,12 @@ +2005-07-08 Helge Hess + + * v0.9.92 + + * SOGoMailManager.m, SOGoMailConnectionEntry.m: added caching of + per-folder permissions to avoid an IMAP4 query on each folder click + + * SOGoMailFolder.m: fixed an inconsistency in the naming of flags + 2005-07-07 Helge Hess * SOGoMailManager.m, SOGoMailFolder.m: added methods to "bulk add" diff --git a/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.h b/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.h index 4b8a9017..0e3fcfc2 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.h +++ b/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.h @@ -28,9 +28,15 @@ SOGoMailConnectionEntry A cached connection to an IMAP4 server plus some cached objects. + + It caches: + - the folder hierarchy + - uid sets? + - 'myrights' permissions of mailboxes + ? */ -@class NSString, NSDate, NSArray, NSDictionary, NSURL; +@class NSString, NSDate, NSArray, NSDictionary, NSURL, NSMutableDictionary; @class NGImap4Client; @interface SOGoMailConnectionEntry : NSObject @@ -39,7 +45,12 @@ NGImap4Client *client; NSString *password; NSDate *creationTime; + + /* hierarchy cache */ NSDictionary *subfolders; + + /* permission cache */ + NSMutableDictionary *urlToRights; /* uids cache */ NSArray *cachedUIDs; @@ -64,6 +75,9 @@ - (void)cacheUIDs:(NSArray *)_uids forURL:(NSURL *)_url qualifier:(id)_q sortOrdering:(id)_so; +- (NSString *)cachedMyRightsForURL:(NSURL *)_url; +- (void)cacheMyRights:(NSString *)_rights forURL:(NSURL *)_url; + - (void)flushMailCaches; @end diff --git a/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.m b/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.m index 9875bd9d..a113fda7 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.m +++ b/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.m @@ -43,6 +43,7 @@ } - (void)dealloc { + [self->urlToRights release]; [self->cachedUIDs release]; [self->uidFolderURL release]; [self->uidSortOrdering release]; @@ -73,10 +74,23 @@ return self->subfolders; } - (void)flushFolderHierarchyCache { - [self->subfolders release]; - self->subfolders = nil; + [self->subfolders release]; self->subfolders = nil; + [self->urlToRights release]; self->urlToRights = nil; } +/* rights */ + +- (NSString *)cachedMyRightsForURL:(NSURL *)_url { + return (_url != nil) ? [self->urlToRights objectForKey:_url] : nil; +} +- (void)cacheMyRights:(NSString *)_rights forURL:(NSURL *)_url { + if (self->urlToRights == nil) + self->urlToRights = [[NSMutableDictionary alloc] initWithCapacity:8]; + [self->urlToRights setObject:_rights forKey:_url]; +} + +/* UIDs */ + - (id)cachedUIDsForURL:(NSURL *)_url qualifier:(id)_q sortOrdering:(id)_so { if (_q != nil) return nil; @@ -100,9 +114,9 @@ } - (void)flushMailCaches { - ASSIGNCOPY(self->uidSortOrdering, nil); - ASSIGNCOPY(self->uidFolderURL, nil); - ASSIGNCOPY(self->cachedUIDs, nil); + ASSIGN(self->uidSortOrdering, nil); + ASSIGN(self->uidFolderURL, nil); + ASSIGN(self->cachedUIDs, nil); } @end /* SOGoMailConnectionEntry */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailFolder.h b/SOGo/SoObjects/Mailer/SOGoMailFolder.h index 1978a001..c4e49612 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailFolder.h +++ b/SOGo/SoObjects/Mailer/SOGoMailFolder.h @@ -42,7 +42,7 @@ NSString *folderType; SOGoMailboxInfo *selectInfo; struct { - int didCheckACL:1; + int didCheckMyRights:1; int isDeleteAndExpungeAllowed:1; int reserved:30; } somfFlags; diff --git a/SOGo/SoObjects/Mailer/SOGoMailFolder.m b/SOGo/SoObjects/Mailer/SOGoMailFolder.m index c901e19f..262278f0 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailFolder.m +++ b/SOGo/SoObjects/Mailer/SOGoMailFolder.m @@ -111,7 +111,7 @@ - (void)_loadACLPermissionFlags { NSString *rights; - if (self->somfFlags.didCheckACL) + if (self->somfFlags.didCheckMyRights) return; rights = [[self mailManager] myRightsForMailboxAtURL:[self imap4URL] @@ -121,7 +121,7 @@ return; } - self->somfFlags.didCheckACL = 1; + self->somfFlags.didCheckMyRights = 1; self->somfFlags.isDeleteAndExpungeAllowed = [rights rangeOfString:@"d"].length > 0 ? 1 : 0; } diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.m b/SOGo/SoObjects/Mailer/SOGoMailManager.m index 4a36a024..ea9e1fcf 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.m +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.m @@ -43,7 +43,7 @@ static BOOL debugKeys = NO; static BOOL poolingOff = NO; static BOOL alwaysSelect = NO; static BOOL onlyFetchInbox = NO; -static NSTimeInterval PoolScanInterval = 5 * 60; +static NSTimeInterval PoolScanInterval = 5 * 60 /* every five minutes */; static NSString *imap4Separator = nil; + (void)initialize { @@ -1009,6 +1009,13 @@ static NSString *imap4Separator = nil; return [NSException exceptionWithHTTPStatus:404 /* Not Found */ reason:@"did not find IMAP4 folder (no entry)"]; } + + /* check cache */ + + if ((result = [entry cachedMyRightsForURL:_url]) != nil) + return result; + + /* run IMAP4 op */ folderName = [self imap4FolderNameForURL:_url]; result = [[entry client] myRights:folderName]; @@ -1017,8 +1024,12 @@ static NSString *imap4Separator = nil; return [NSException exceptionWithHTTPStatus:404 /* Not Found */ reason:@"did not find myrights for IMAP4 folder"]; } + + /* cache results */ - return [result valueForKey:@"myrights"]; + if ((result = [result valueForKey:@"myrights"]) != nil) + [entry cacheMyRights:result forURL:_url]; + return result; } /* bulk flag adding (eg used for empty/trash) */ diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 94cce5ea..8fcde6b1 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=91 +SUBMINOR_VERSION:=92 # v0.9.91 requires libNGMime v4.5.222 # v0.9.69 requires libNGMime v4.5.210