From 3c0e534d111e9e98d0bb7f80fd3fb5f0b06e3275 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Sat, 6 Oct 2012 14:51:26 -0400 Subject: [PATCH] Keep unresolved users in the cache too, to avoid useless queries to the user database --- SoObjects/SOGo/SOGoUserManager.m | 48 +++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index e62c21304..acba8c7f5 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -25,6 +25,7 @@ #import #import #import +#import #import #import #import @@ -43,8 +44,15 @@ #import "SOGoConstants.h" #import "SOGoSource.h" +static Class NSNullK; + @implementation SOGoUserManagerRegistry ++ (void) initialize +{ + NSNullK = [NSNull class]; +} + + (id) sharedRegistry { static id sharedRegistry = nil; @@ -691,18 +699,20 @@ [[SOGoCache sharedCache] setUserAttributes: [newUser jsonRepresentation] forLogin: login]; - - key = [newUser objectForKey: @"c_uid"]; - if (key && ![key isEqualToString: login]) - [[SOGoCache sharedCache] - setUserAttributes: [newUser jsonRepresentation] - forLogin: key]; + if (![newUser isKindOfClass: NSNullK]) + { + key = [newUser objectForKey: @"c_uid"]; + if (key && ![key isEqualToString: login]) + [[SOGoCache sharedCache] + setUserAttributes: [newUser jsonRepresentation] + forLogin: key]; - emails = [[newUser objectForKey: @"emails"] objectEnumerator]; - while ((key = [emails nextObject])) - [[SOGoCache sharedCache] - setUserAttributes: [newUser jsonRepresentation] - forLogin: key]; + emails = [[newUser objectForKey: @"emails"] objectEnumerator]; + while ((key = [emails nextObject])) + [[SOGoCache sharedCache] + setUserAttributes: [newUser jsonRepresentation] + forLogin: key]; + } } - (NSMutableDictionary *) _contactInfosForAnonymous @@ -787,7 +797,9 @@ cacheUid = aUID; jsonUser = [[SOGoCache sharedCache] userAttributesForLogin: cacheUid]; currentUser = [jsonUser objectFromJSONString]; - if (!([currentUser objectForKey: @"emails"] + if ([currentUser isKindOfClass: NSNullK]) + currentUser = nil; + else if (!([currentUser objectForKey: @"emails"] && [currentUser objectForKey: @"cn"])) { // We make sure that we either have no occurence of a cache entry or @@ -808,11 +820,15 @@ inDomain: domain]; if (newUser) { - if ([[currentUser objectForKey: @"c_uid"] length] > 0) - [self _retainUser: currentUser + if ([[currentUser objectForKey: @"c_uid"] length] == 0) + { + [self _retainUser: (NSDictionary *) [NSNull null] + withLogin: cacheUid]; + currentUser = nil; + } + else + [self _retainUser: currentUser withLogin: cacheUid]; - else - currentUser = nil; } } }