Working on issue #981 - Improved performance to search only needed arguments of a LDAP entry.

This commit is contained in:
Thorsten Eckel 2017-05-05 10:48:40 +02:00
parent d13bf09fa8
commit cbc5af2b5b
3 changed files with 12 additions and 4 deletions

View file

@ -24,7 +24,13 @@ module Import
import_job = kargs[:import_job]
import_job_count = 0
@ldap.search(config[:user_filter]) do |entry|
# limit the fetched attributes for an entry to only
# those which are needed to improve the performance
relevant_attributes = config[:user_attributes].keys
relevant_attributes.push('dn')
@ldap.search(config[:user_filter], attributes: relevant_attributes) do |entry|
backend_instance = create_instance(entry, config, user_roles, signup_role_ids, kargs)
post_import_hook(entry, backend_instance, config, user_roles, signup_role_ids, kargs)

View file

@ -54,6 +54,7 @@ class Ldap
# @param filter [String] The filter that should get applied to the search.
# @param base [String] The base DN on which the search should get executed. Default is initialization parameter.
# @param scope [Net::LDAP::SearchScope] The search scope as defined in Net::LDAP SearchScopes. Default is WholeSubtree.
# @param attributes [Array<String>] Limits the requested entry attributes to the given list of attributes which increses the performance.
#
# @example
# ldap.search('(objectClass=group)') do |entry|
@ -62,7 +63,7 @@ class Ldap
# #=> <Net::LDAP::Entry...>
#
# @return [true] Returns always true
def search(filter, base: nil, scope: nil)
def search(filter, base: nil, scope: nil, attributes: nil)
base ||= base_dn()
scope ||= Net::LDAP::SearchScope_WholeSubtree
@ -71,6 +72,7 @@ class Ldap
base: base,
filter: filter,
scope: scope,
attributes: attributes,
return_result: false, # improves performance
) do |entry|
# needed for the #entries? method -> returns nil on break

View file

@ -58,7 +58,7 @@ class Ldap
return {} if filter.blank?
groups = {}
@ldap.search(filter, base: base_dn) { |entry|
@ldap.search(filter, base: base_dn, attributes: %w(dn)) { |entry|
groups[entry.dn.downcase] = entry.dn.downcase
}
groups
@ -80,7 +80,7 @@ class Ldap
filter ||= filter()
result = {}
@ldap.search(filter) do |entry|
@ldap.search(filter, attributes: %w(dn member)) do |entry|
members = entry[:member]
next if members.blank?