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