Skip to content

Commit

Permalink
fix(core): avoid caching group members per instance
Browse files Browse the repository at this point in the history
  • Loading branch information
extrafu committed Jun 8, 2020
1 parent 056004b commit 0ff0d43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion SoObjects/SOGo/LDAPSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
NSDictionary *_contactMapping;
NSArray *_contactObjectClasses;
NSArray *_groupObjectClasses;
NSMutableArray *_members;
NSMutableDictionary *_members;

NSDictionary *_modulesConstraints;

Expand Down
28 changes: 16 additions & 12 deletions SoObjects/SOGo/LDAPSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ - (id) init
// "name" expands to sn, displayname and cn
_searchFields = [[NSArray arrayWithObjects: @"name", @"mail", @"telephonenumber", nil] retain];
_groupObjectClasses = [[NSArray arrayWithObjects: @"group", @"groupofnames", @"groupofuniquenames", @"posixgroup", nil] retain];
_members = nil;
_members = [[NSMutableDictionary alloc] init];
_IMAPHostField = nil;
_IMAPLoginField = nil;
_SieveHostField = nil;
Expand Down Expand Up @@ -2026,17 +2026,19 @@ - (void) updateBaseDNFromLogin: (NSString *) theLogin

- (NSArray *) membersForGroupWithUID: (NSString *) uid
{
NSMutableArray *dns, *uids, *logins;
NSMutableArray *dns, *uids, *logins, *members;
NSAutoreleasePool *pool;
NSString *dn, *login;
SOGoUserManager *um;
NGLdapEntry *entry;
NSDictionary *d;
SOGoUser *user;
NSArray *o;
NSAutoreleasePool *pool;

id result;
int i, c;
NGLdapEntry *entry;

if (!_members)
if (!(result = [_members objectForKey: uid]))
{
if ([uid hasPrefix: @"@"])
uid = [uid substringFromIndex: 1];
Expand All @@ -2045,7 +2047,7 @@ - (NSArray *) membersForGroupWithUID: (NSString *) uid

if (entry)
{
_members = [[NSMutableArray alloc] init];
members = [NSMutableArray array];
uids = [NSMutableArray array];
dns = [NSMutableArray array];
logins = [NSMutableArray array];
Expand Down Expand Up @@ -2084,7 +2086,7 @@ - (NSArray *) membersForGroupWithUID: (NSString *) uid
if (user)
{
[logins addObject: login];
[_members addObject: [NSDictionary dictionaryWithObject: login
[members addObject: [NSDictionary dictionaryWithObject: login
forKey: @"c_uid"]];
}
[pool release];
Expand All @@ -2099,7 +2101,7 @@ - (NSArray *) membersForGroupWithUID: (NSString *) uid
if (user)
{
[logins addObject: login];
[_members addObject: [NSDictionary dictionaryWithObject: login
[members addObject: [NSDictionary dictionaryWithObject: login
forKey: @"c_uid"]];
}
[pool release];
Expand All @@ -2108,6 +2110,7 @@ - (NSArray *) membersForGroupWithUID: (NSString *) uid

// We are done fetching members, let's cache the members of the group
// (ie., their UIDs) in memcached to speed up -hasMemberWithUID.
[_members setObject: members forKey: uid];
[[SOGoCache sharedCache] setValue: [logins componentsJoinedByString: @","]
forKey: [NSString stringWithFormat: @"%@+%@", uid, _domain]];
}
Expand All @@ -2120,7 +2123,7 @@ - (NSArray *) membersForGroupWithUID: (NSString *) uid
}
}

return _members;
return result;
}

//
Expand All @@ -2129,6 +2132,7 @@ - (NSArray *) membersForGroupWithUID: (NSString *) uid
- (BOOL) groupWithUIDHasMemberWithUID: (NSString *) uid
memberUid: (NSString *) memberUid
{
id result;
BOOL rc;

rc = NO;
Expand All @@ -2137,15 +2141,15 @@ - (BOOL) groupWithUIDHasMemberWithUID: (NSString *) uid
// Otherwise, we fallback on memcached in order to avoid
// decomposing the group all the time just to see if a user
// is a member of it.
if (_members)
if ((result = [_members objectForKey: uid]))
{
NSString *currentUID;
int count, max;

max = [_members count];
max = [result count];
for (count = 0; !rc && count < max; count++)
{
currentUID = [[_members objectAtIndex: count] objectForKey: @"c_uid"];
currentUID = [[result objectAtIndex: count] objectForKey: @"c_uid"];
rc = [memberUid isEqualToString: currentUID];
}
}
Expand Down

0 comments on commit 0ff0d43

Please sign in to comment.