diff --git a/ChangeLog b/ChangeLog index 62681e20d..d747e6bd2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2010-03-30 Wolfgang Sourdeau + * SoObjects/Contacts/SOGoContactSourceFolder.m + (-lookupName:inContext:acquire:): lookup the object in the + "childRecords" cache prior to fetching it from the source. If the + latter happens, the resulting record is cached. + (-lookupContactsWithFilter:sortBy:ordering:): populate the + "childRecords" cache with resulting records to avoid further + lookups of the same data. + * SoObjects/SOGo/LDAPSource.m (-changePasswordForLogin:oldPassword:newPassword:perr:): fixed a typo that could potentially cause crashes. diff --git a/SoObjects/Contacts/SOGoContactSourceFolder.h b/SoObjects/Contacts/SOGoContactSourceFolder.h index b58dd571f..5cde076b7 100644 --- a/SoObjects/Contacts/SOGoContactSourceFolder.h +++ b/SoObjects/Contacts/SOGoContactSourceFolder.h @@ -33,7 +33,7 @@ @interface SOGoContactSourceFolder : SOGoFolder { id source; - NSMutableDictionary *entries; + NSMutableDictionary *childRecords; } + (id) folderWithName: (NSString *) aName diff --git a/SoObjects/Contacts/SOGoContactSourceFolder.m b/SoObjects/Contacts/SOGoContactSourceFolder.m index 5b70fdf51..e8cbd5863 100644 --- a/SoObjects/Contacts/SOGoContactSourceFolder.m +++ b/SoObjects/Contacts/SOGoContactSourceFolder.m @@ -39,6 +39,8 @@ #import #import +#import +#import #import #import "SOGoContactLDIFEntry.h" @@ -62,10 +64,10 @@ component = [self lookupName: name inContext: context acquire: NO]; if ([component isKindOfClass: [NSException class]]) - { - [self logWithFormat: @"Object with name '%@' not found. You likely have a LDAP configuration issue.", name]; - return; - } + { + [self logWithFormat: @"Object with name '%@' not found. You likely have a LDAP configuration issue.", name]; + return; + } [r appendContentString: @" \r\n"]; [r appendContentString: @" "]; @@ -78,7 +80,7 @@ [r appendContentString: @" \r\n"]; [r appendContentString: @" \r\n"]; etagLine = [NSString stringWithFormat: @" %@\r\n", - [component davEntityTag]]; + [component davEntityTag]]; [r appendContentString: etagLine]; [r appendContentString: @" \r\n"]; [r appendContentString: @" HTTP/1.1 200 OK\r\n"]; @@ -109,7 +111,7 @@ { if ((self = [super init])) { - entries = nil; + childRecords = [NSMutableDictionary new]; source = nil; } @@ -133,7 +135,7 @@ - (void) dealloc { - [entries release]; + [childRecords release]; [source release]; [super dealloc]; } @@ -175,13 +177,18 @@ if (!obj) { - ldifEntry = [source lookupContactEntry: objectName]; + ldifEntry = [childRecords objectForKey: objectName]; + if (!ldifEntry) + { + ldifEntry = [source lookupContactEntry: objectName]; + [childRecords setObject: ldifEntry forKey: objectName]; + } if (ldifEntry) - obj = [SOGoContactLDIFEntry contactEntryWithName: objectName - withLDIFEntry: ldifEntry - inContainer: self]; + obj = [SOGoContactLDIFEntry contactEntryWithName: objectName + withLDIFEntry: ldifEntry + inContainer: self]; else - obj = [NSException exceptionWithHTTPStatus: 404]; + obj = [NSException exceptionWithHTTPStatus: 404]; } return obj; @@ -200,16 +207,12 @@ NSMutableDictionary *newRecord; NSString *data; - newRecords = [[NSMutableArray alloc] initWithCapacity: [records count]]; - [newRecords autorelease]; + newRecords = [NSMutableArray arrayWithCapacity: [records count]]; oldRecords = [records objectEnumerator]; - oldRecord = [oldRecords nextObject]; - while (oldRecord) + while ((oldRecord = [oldRecords nextObject])) { newRecord = [NSMutableDictionary new]; - [newRecord autorelease]; - [newRecord setObject: [oldRecord objectForKey: @"c_uid"] forKey: @"c_uid"]; [newRecord setObject: [oldRecord objectForKey: @"c_name"] @@ -259,7 +262,7 @@ [newRecord setObject: data forKey: @"contactInfo"]; [newRecords addObject: newRecord]; - oldRecord = [oldRecords nextObject]; + [newRecord release]; } return newRecords; @@ -276,8 +279,11 @@ if (filter && [filter length] > 0) { - records = [self _flattenedRecords: - [source fetchContactsMatching: filter]]; + records = [source fetchContactsMatching: filter]; + [childRecords setObjects: records + forKeys: [records objectsForKey: @"c_name" + notFoundMarker: nil]]; + records = [self _flattenedRecords: records]; ordering = [EOSortOrdering sortOrderingWithKey: sortKey selector: ((sortOrdering == NSOrderedDescending)