diff --git a/SoObjects/SOGo/SOGoSQLUserProfile.m b/SoObjects/SOGo/SOGoSQLUserProfile.m index 06d9e3756..54ee5d1ed 100644 --- a/SoObjects/SOGo/SOGoSQLUserProfile.m +++ b/SoObjects/SOGo/SOGoSQLUserProfile.m @@ -27,6 +27,7 @@ #import #import #import +#import #import "SOGoSystemDefaults.h" @@ -35,6 +36,7 @@ static NSURL *tableURL = nil; static NSString *uidColumnName = @"c_uid"; static EOAttribute *textColumn = nil; +static const NSString *kCDefaultsLenKey = @"kCDefaultsLenKey"; @implementation SOGoSQLUserProfile @@ -248,22 +250,34 @@ static EOAttribute *textColumn = nil; EOAdaptorContext *context; NSArray *attrs; NSDictionary *infos; + SOGoCache *cache; + NSNumberFormatter *formatter; r = 65535; - - cm = [GCSChannelManager defaultChannelManager]; - channel = [cm acquireOpenChannelForURL: tableURL]; - sql = [NSString stringWithFormat: @"select character_octet_length as CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '%@' AND column_name = 'c_defaults'", [tableURL gcsTableName]]; - ex = [channel evaluateExpressionX: sql]; - if (!ex) { - attrs = [channel describeResults: NO]; - infos = [channel fetchAttributes: attrs withZone: NULL]; - [cm releaseChannel: channel immediately: YES]; - if (infos && [infos objectForKey:@"CHARACTER_MAXIMUM_LENGTH"]) { - r = [[infos objectForKey:@"CHARACTER_MAXIMUM_LENGTH"] longLongValue]; - } + + cache = [SOGoCache sharedCache]; + if ([cache valueForKey:kCDefaultsLenKey]) { + formatter = [[NSNumberFormatter alloc] init]; + formatter.numberStyle = NSNumberFormatterDecimalStyle; + r = [[formatter numberFromString: [cache valueForKey:kCDefaultsLenKey]] unsignedLongLongValue]; + [formatter release]; + } else { + cm = [GCSChannelManager defaultChannelManager]; + channel = [cm acquireOpenChannelForURL: tableURL]; + sql = [NSString stringWithFormat: @"select character_octet_length as CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '%@' AND column_name = 'c_defaults'", [tableURL gcsTableName]]; + ex = [channel evaluateExpressionX: sql]; + if (!ex) { + attrs = [channel describeResults: NO]; + infos = [channel fetchAttributes: attrs withZone: NULL]; + [cm releaseChannel: channel immediately: YES]; + if (infos && [infos objectForKey:@"CHARACTER_MAXIMUM_LENGTH"]) { + r = [[infos objectForKey:@"CHARACTER_MAXIMUM_LENGTH"] longLongValue]; + [cache setValue: [[NSNumber numberWithUnsignedLongLong: r] stringValue] forKey: kCDefaultsLenKey]; + } + } } + return r; }