Working on issue #981 - Improved performance to search only needed arguments of a LDAP entry.
This commit is contained in:
parent
d13bf09fa8
commit
cbc5af2b5b
3 changed files with 12 additions and 4 deletions
|
@ -24,7 +24,13 @@ module Import
|
||||||
|
|
||||||
import_job = kargs[:import_job]
|
import_job = kargs[:import_job]
|
||||||
import_job_count = 0
|
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)
|
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)
|
post_import_hook(entry, backend_instance, config, user_roles, signup_role_ids, kargs)
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ class Ldap
|
||||||
# @param filter [String] The filter that should get applied to the search.
|
# @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 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 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
|
# @example
|
||||||
# ldap.search('(objectClass=group)') do |entry|
|
# ldap.search('(objectClass=group)') do |entry|
|
||||||
|
@ -62,7 +63,7 @@ class Ldap
|
||||||
# #=> <Net::LDAP::Entry...>
|
# #=> <Net::LDAP::Entry...>
|
||||||
#
|
#
|
||||||
# @return [true] Returns always true
|
# @return [true] Returns always true
|
||||||
def search(filter, base: nil, scope: nil)
|
def search(filter, base: nil, scope: nil, attributes: nil)
|
||||||
|
|
||||||
base ||= base_dn()
|
base ||= base_dn()
|
||||||
scope ||= Net::LDAP::SearchScope_WholeSubtree
|
scope ||= Net::LDAP::SearchScope_WholeSubtree
|
||||||
|
@ -71,6 +72,7 @@ class Ldap
|
||||||
base: base,
|
base: base,
|
||||||
filter: filter,
|
filter: filter,
|
||||||
scope: scope,
|
scope: scope,
|
||||||
|
attributes: attributes,
|
||||||
return_result: false, # improves performance
|
return_result: false, # improves performance
|
||||||
) do |entry|
|
) do |entry|
|
||||||
# needed for the #entries? method -> returns nil on break
|
# needed for the #entries? method -> returns nil on break
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Ldap
|
||||||
return {} if filter.blank?
|
return {} if filter.blank?
|
||||||
|
|
||||||
groups = {}
|
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[entry.dn.downcase] = entry.dn.downcase
|
||||||
}
|
}
|
||||||
groups
|
groups
|
||||||
|
@ -80,7 +80,7 @@ class Ldap
|
||||||
filter ||= filter()
|
filter ||= filter()
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
@ldap.search(filter) do |entry|
|
@ldap.search(filter, attributes: %w(dn member)) do |entry|
|
||||||
|
|
||||||
members = entry[:member]
|
members = entry[:member]
|
||||||
next if members.blank?
|
next if members.blank?
|
||||||
|
|
Loading…
Reference in a new issue