Return NSDictionary contact entries from [MembershipAwareSource membersForGroupWithUID] instead of SOGoUser objects.
Optimization for user sources that are capable of fetching lists of group members at once, might save a lot of expensive SOGoUser lookups.pull/263/head
parent
2e98929900
commit
278d4ab4cb
|
@ -438,36 +438,38 @@ static Class iCalEventK = nil;
|
|||
if (rc)
|
||||
{
|
||||
#warning Duplicated code from SOGoGCSFolder subscribeUserOrGroup
|
||||
dict = [[SOGoUserManager sharedUserManager] contactInfosForUserWithUIDorEmail: theIdentifier];
|
||||
dict = [[SOGoUserManager sharedUserManager] contactInfosForUserWithUIDorEmail: theIdentifier];
|
||||
|
||||
if (dict && [[dict objectForKey: @"isGroup"] boolValue])
|
||||
{
|
||||
id <SOGoSource> source;
|
||||
if (dict && [[dict objectForKey: @"isGroup"] boolValue])
|
||||
{
|
||||
id <SOGoSource> source;
|
||||
|
||||
source = [[SOGoUserManager sharedUserManager] sourceWithID: [dict objectForKey: @"SOGoSource"]];
|
||||
if ([source conformsToProtocol:@protocol(MembershipAwareSource)])
|
||||
{
|
||||
allUsers = [NSMutableArray arrayWithArray: [(id<MembershipAwareSource>)(source) membersForGroupWithUID: [dict objectForKey: @"c_uid"]]];
|
||||
source = [[SOGoUserManager sharedUserManager] sourceWithID: [dict objectForKey: @"SOGoSource"]];
|
||||
if ([source conformsToProtocol:@protocol(MembershipAwareSource)])
|
||||
{
|
||||
NSArray *members = [(id<MembershipAwareSource>)(source) membersForGroupWithUID: [dict objectForKey: @"c_uid"]];
|
||||
allUsers = [NSMutableArray array];
|
||||
|
||||
// We remove the active user from the group (if present) in order to
|
||||
// not subscribe him to their own resource!
|
||||
[allUsers removeObject: [context activeUser]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sogoUser = [SOGoUser userWithLogin: theIdentifier roles: nil];
|
||||
|
||||
if (sogoUser)
|
||||
allUsers = [NSArray arrayWithObject: sogoUser];
|
||||
else
|
||||
allUsers = [NSArray array];
|
||||
}
|
||||
for (i = 0; i < [members count]; i++)
|
||||
{
|
||||
[allUsers addObject: [[members objectAtIndex: i] objectForKey: @"c_uid"]];
|
||||
}
|
||||
// We remove the active user from the group (if present) in order to
|
||||
// not subscribe him to their own resource!
|
||||
[allUsers removeObject: [[context activeUser] login]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dict)
|
||||
allUsers = [NSArray arrayWithObject: [dict objectForKey: @"c_uid"]];
|
||||
else
|
||||
allUsers = [NSArray array];
|
||||
}
|
||||
|
||||
for (i = 0; i < [allUsers count]; i++)
|
||||
{
|
||||
sogoUser = [allUsers objectAtIndex: i];
|
||||
us = [sogoUser userSettings];
|
||||
us = [SOGoUserSettings settingsForUser: [allUsers objectAtIndex: i]];
|
||||
moduleSettings = [us objectForKey: [container nameInContainer]];
|
||||
if (!(moduleSettings
|
||||
&& [moduleSettings isKindOfClass: [NSMutableDictionary class]]))
|
||||
|
|
|
@ -555,7 +555,7 @@
|
|||
{
|
||||
iCalPerson *person;
|
||||
NSArray *members;
|
||||
SOGoUser *user;
|
||||
NSDictionary *user;
|
||||
id <SOGoSource> source;
|
||||
|
||||
// We did decompose a group...
|
||||
|
@ -572,10 +572,10 @@
|
|||
|
||||
// If the organizer is part of the group, we skip it from
|
||||
// the addition to the attendees' list
|
||||
if ([user hasEmail: organizerEmail])
|
||||
if ([[user objectForKey: @"c_emails"] containsObject: organizerEmail])
|
||||
continue;
|
||||
|
||||
person = [self iCalPersonWithUID: [user login]];
|
||||
person = [self iCalPersonWithUID: [user objectForKey: @"c_uid"]];
|
||||
[person setTag: @"ATTENDEE"];
|
||||
[person setParticipationStatus: [currentAttendee participationStatus]];
|
||||
[person setRsvp: [currentAttendee rsvp]];
|
||||
|
|
|
@ -1373,6 +1373,30 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses
|
|||
return login;
|
||||
}
|
||||
|
||||
- (NSDictionary *) lookupContactEntryByDN: (NSString *) theDN
|
||||
{
|
||||
NGLdapConnection *ldapConnection;
|
||||
NGLdapEntry *ldapEntry;
|
||||
EOQualifier *qualifier;
|
||||
NSDictionary *ldifRecord;
|
||||
|
||||
ldifRecord = nil;
|
||||
qualifier = nil;
|
||||
|
||||
ldapConnection = [self _ldapConnection];
|
||||
|
||||
if (_filter)
|
||||
qualifier = [EOQualifier qualifierWithQualifierFormat: _filter];
|
||||
|
||||
ldapEntry = [ldapConnection entryAtDN: theDN
|
||||
qualifier: qualifier
|
||||
attributes: [NSArray arrayWithObject: @"*"]];
|
||||
if (ldapEntry)
|
||||
ldifRecord = [self _convertLDAPEntryToContact: ldapEntry];
|
||||
|
||||
return ldifRecord;
|
||||
}
|
||||
|
||||
- (NSString *) lookupDNByLogin: (NSString *) theLogin
|
||||
{
|
||||
return [[SOGoCache sharedCache] distinguishedNameForLogin: theLogin];
|
||||
|
@ -2002,7 +2026,7 @@ _makeLDAPChanges (NGLdapConnection *ldapConnection,
|
|||
NSString *dn, *login;
|
||||
SOGoUserManager *um;
|
||||
NSDictionary *d;
|
||||
SOGoUser *user;
|
||||
NSDictionary *user;
|
||||
NSArray *o;
|
||||
NSAutoreleasePool *pool;
|
||||
int i, c;
|
||||
|
@ -2050,11 +2074,10 @@ _makeLDAPChanges (NGLdapConnection *ldapConnection,
|
|||
{
|
||||
pool = [NSAutoreleasePool new];
|
||||
dn = [dns objectAtIndex: i];
|
||||
login = [um getLoginForDN: [dn lowercaseString]];
|
||||
user = [SOGoUser userWithLogin: login roles: nil];
|
||||
user = [self lookupContactEntryByDN: dn];
|
||||
if (user)
|
||||
{
|
||||
[logins addObject: login];
|
||||
[logins addObject: [user objectForKey: @"c_uid"]];
|
||||
[members addObject: user];
|
||||
}
|
||||
[pool release];
|
||||
|
@ -2065,11 +2088,11 @@ _makeLDAPChanges (NGLdapConnection *ldapConnection,
|
|||
{
|
||||
pool = [NSAutoreleasePool new];
|
||||
login = [uids objectAtIndex: i];
|
||||
user = [SOGoUser userWithLogin: login roles: nil];
|
||||
user = [self lookupContactEntry: login inDomain: nil];
|
||||
|
||||
if (user)
|
||||
{
|
||||
[logins addObject: [user loginInDomain]];
|
||||
[logins addObject: [user objectForKey: @"c_uid"]];
|
||||
[members addObject: user];
|
||||
}
|
||||
[pool release];
|
||||
|
|
|
@ -927,7 +927,6 @@ static NSArray *childRecordFields = nil;
|
|||
NSMutableArray *allUsers;
|
||||
SOGoUserSettings *us;
|
||||
NSDictionary *dict;
|
||||
SOGoUser *sogoUser;
|
||||
BOOL rc;
|
||||
int i;
|
||||
|
||||
|
@ -940,19 +939,22 @@ static NSArray *childRecordFields = nil;
|
|||
source = [[SOGoUserManager sharedUserManager] sourceWithID: [dict objectForKey: @"SOGoSource"]];
|
||||
if ([source conformsToProtocol:@protocol(MembershipAwareSource)])
|
||||
{
|
||||
allUsers = [NSMutableArray arrayWithArray: [(id<MembershipAwareSource>)(source) membersForGroupWithUID: [dict objectForKey: @"c_uid"]]];
|
||||
NSArray *members = [(id<MembershipAwareSource>)(source) membersForGroupWithUID: [dict objectForKey: @"c_uid"]];
|
||||
allUsers = [NSMutableArray array];
|
||||
|
||||
for (i = 0; i < [members count]; i++)
|
||||
{
|
||||
[allUsers addObject: [[members objectAtIndex: i] objectForKey: @"c_uid"]];
|
||||
}
|
||||
// We remove the active user from the group (if present) in order to
|
||||
// not subscribe him to their own resource!
|
||||
[allUsers removeObject: [context activeUser]];
|
||||
[allUsers removeObject: [[context activeUser] login]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sogoUser = [SOGoUser userWithLogin: theIdentifier roles: nil];
|
||||
|
||||
if (sogoUser)
|
||||
allUsers = [NSArray arrayWithObject: sogoUser];
|
||||
if (dict)
|
||||
allUsers = [NSArray arrayWithObject: [dict objectForKey: @"c_uid"]];
|
||||
else
|
||||
allUsers = [NSArray array];
|
||||
}
|
||||
|
@ -965,8 +967,7 @@ static NSArray *childRecordFields = nil;
|
|||
|
||||
for (i = 0; i < [allUsers count]; i++)
|
||||
{
|
||||
sogoUser = [allUsers objectAtIndex: i];
|
||||
us = [sogoUser userSettings];
|
||||
us = [SOGoUserSettings settingsForUser: [allUsers objectAtIndex: i]];
|
||||
moduleSettings = [us objectForKey: [container nameInContainer]];
|
||||
if (!(moduleSettings
|
||||
&& [moduleSettings isKindOfClass: [NSMutableDictionary class]]))
|
||||
|
@ -1773,7 +1774,7 @@ static NSArray *childRecordFields = nil;
|
|||
if ([source conformsToProtocol:@protocol(MembershipAwareSource)])
|
||||
{
|
||||
NSArray *members;
|
||||
SOGoUser *user;
|
||||
NSDictionary *user;
|
||||
unsigned int j;
|
||||
|
||||
// Fetch members to remove them from the cache along the group
|
||||
|
@ -1781,7 +1782,7 @@ static NSArray *childRecordFields = nil;
|
|||
for (j = 0; j < [members count]; j++)
|
||||
{
|
||||
user = [members objectAtIndex: j];
|
||||
[groupsMembers addObject: [user login]];
|
||||
[groupsMembers addObject: [user objectForKey: @"c_uid"]];
|
||||
}
|
||||
|
||||
if (![uid hasPrefix: @"@"])
|
||||
|
|
|
@ -396,7 +396,7 @@
|
|||
NSString *email;
|
||||
SOGoObject <SOGoContactObject> *contact;
|
||||
SOGoObject <SOGoSource> *source;
|
||||
SOGoUser *user;
|
||||
NSDictionary *user;
|
||||
id <WOActionResults> result;
|
||||
unsigned int i, max;
|
||||
|
||||
|
@ -416,14 +416,14 @@
|
|||
{
|
||||
user = [allUsers objectAtIndex: i];
|
||||
allUserEmails = [NSMutableArray array];
|
||||
emails = [[user allEmails] objectEnumerator];
|
||||
emails = [[user objectForKey: @"c_emails"] objectEnumerator];
|
||||
while ((email = [emails nextObject])) {
|
||||
[allUserEmails addObject: [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
email, @"value", @"work", @"type", nil]];
|
||||
}
|
||||
userData = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
[user loginInDomain], @"c_uid",
|
||||
[user cn], @"c_cn",
|
||||
[user objectForKey: @"c_uid"], @"c_uid",
|
||||
[user objectForKey: @"c_cn"], @"c_cn",
|
||||
allUserEmails, @"emails", nil];
|
||||
[allUsersData addObject: userData];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue