perf(core): cache the schema of LDAP user sources

pull/298/head
Francis Lachapelle 2021-05-14 11:56:13 -04:00
parent debcbd16db
commit d0056d3b27
3 changed files with 33 additions and 7 deletions

View File

@ -440,6 +440,8 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses
- (NGLdapConnection *) _ldapConnection
{
NGLdapConnection *ldapConnection;
NSString *value, *key;
SOGoCache *cache;
NS_DURING
{
@ -459,7 +461,20 @@ groupObjectClasses: (NSArray *) newGroupObjectClasses
if (!_schema)
{
_schema = [LDAPSourceSchema new];
[_schema readSchemaFromConnection: ldapConnection];
cache = [SOGoCache sharedCache];
key = [NSString stringWithFormat: @"schema:%@", _sourceID];
value = [cache valueForKey: key];
if (value)
{
[_schema setSchema: (NSMutableDictionary *)[value objectFromJSONString]];
}
else
{
// We go check in the LDAP directory
[_schema readSchemaFromConnection: ldapConnection];
[cache setValue: [_schema jsonRepresentation] forKey: key];
}
}
}
else

View File

@ -1,8 +1,6 @@
/* LDAPSourceSchema.h - this file is part of SOGo
*
* Copyright (C) 2011 Inverse inc
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Copyright (C) 2011-2021 Inverse inc
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -34,11 +32,15 @@
- (void) readSchemaFromConnection: (NGLdapConnection *) conn;
- (void) setSchema: (NSMutableDictionary *) newSchema;
- (NSArray *) fieldsForClass: (NSString *) className;
/* merged list of attributes with unique names */
- (NSArray *) fieldsForClasses: (NSArray *) className;
- (NSString *) jsonRepresentation;
@end
#endif /* LDAPSOURCESCHEMA_H */

View File

@ -1,8 +1,6 @@
/* LDAPSourceSchema.m - this file is part of SOGo
*
* Copyright (C) 2011 Inverse inc
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Copyright (C) 2011-2021 Inverse inc
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -239,6 +237,12 @@ fillSchemaFromEntry (NSMutableDictionary *schema, NGLdapEntry *entry)
}
}
- (void) setSchema: (NSMutableDictionary *) newSchema
{
ASSIGN (schema, newSchema);
[schema release];
}
static void
fillFieldsForClass (NSMutableDictionary *schema, NSString *schemaName,
NSMutableArray *fields)
@ -289,4 +293,9 @@ fillFieldsForClass (NSMutableDictionary *schema, NSString *schemaName,
return [fieldHash allKeys];
}
- (NSString *) jsonRepresentation
{
return [schema jsonRepresentation];
}
@end