From 508f6213774dfb2149012e08189411984d7d2c48 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Wed, 10 May 2017 09:53:03 +0200 Subject: [PATCH] Working on issue #981 - Improved LDAP sync performan by caching entry count result. --- lib/import/ldap/user_factory.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/import/ldap/user_factory.rb b/lib/import/ldap/user_factory.rb index 7b318bf8e..8b6c80aba 100644 --- a/lib/import/ldap/user_factory.rb +++ b/lib/import/ldap/user_factory.rb @@ -51,18 +51,21 @@ module Import def self.pre_import_hook(_records, *_args) super + add_sum_to_statistics + end - #cache_key = "#{@ldap.host}::#{@ldap.port}::#{@ldap.ssl}::#{@ldap.base_dn}" - #if !@dry_run - # sum = Cache.get(cache_key) - #end + def self.add_sum_to_statistics + cache_key = "#{@ldap.host}::#{@ldap.port}::#{@ldap.ssl}::#{@ldap.base_dn}::#{@config[:user_filter]}" + if !@dry_run + sum = Cache.get(cache_key) + end sum ||= @ldap.count(@config[:user_filter]) @statistics[:sum] = sum return if !@dry_run - #Cache.write(cache_key, sum, { expires_in: 1.hour }) + Cache.write(cache_key, sum, { expires_in: 1.hour }) end def self.add_to_statistics(backend_instance)