From: Luca Falavigna Date: Thu, 30 Aug 2012 15:13:33 +0000 (+0000) Subject: Improve performances of get_logins_from_ldap X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5824bf2367f8e9f76266a1567172e86a24d6a1bd;p=dak Improve performances of get_logins_from_ldap Signed-off-by: Luca Falavigna --- diff --git a/dak/queue_report.py b/dak/queue_report.py index a8f74102..a2079e81 100755 --- a/dak/queue_report.py +++ b/dak/queue_report.py @@ -47,7 +47,7 @@ from daklib.dbconn import DBConn, DBSource, has_new_comment, PolicyQueue, \ get_uid_from_fingerprint from daklib.policy import PolicyQueueUploadHandler from daklib.textutils import fix_maintainer -from daklib.utils import get_login_from_ldap +from daklib.utils import get_logins_from_ldap from daklib.dak_exceptions import * Cnf = None @@ -416,6 +416,7 @@ def process_queue(queue, log, rrd_dir): max_source_len = 0 max_version_len = 0 max_arch_len = 0 + logins = get_logins_from_ldap() for i in per_source_items: maintainer = {} maint="" @@ -466,7 +467,8 @@ def process_queue(queue, log, rrd_dir): sponsor_name = get_uid_from_fingerprint(fingerprint).name sponsor_login = get_uid_from_fingerprint(fingerprint).uid if '@' in sponsor_login: - sponsor_login = get_login_from_ldap(fingerprint) + if fingerprint in logins: + sponsor_login = logins[fingerprint] if (sponsor_name != maintainer["maintainername"] and sponsor_name != changeby["changedbyname"] and sponsor_login + '@debian.org' != maintainer["maintaineremail"] and diff --git a/daklib/utils.py b/daklib/utils.py index f702db3f..377d1913 100644 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -1411,7 +1411,7 @@ def gpg_get_key_addresses(fingerprint): ################################################################################ -def get_login_from_ldap(fingerprint): +def get_logins_from_ldap(fingerprint='*'): """retrieve login from LDAP linked to a given fingerprint""" LDAPDn = Cnf['Import-LDAP-Fingerprints::LDAPDn'] @@ -1419,8 +1419,12 @@ def get_login_from_ldap(fingerprint): l = ldap.open(LDAPServer) l.simple_bind_s('','') Attrs = l.search_s(LDAPDn, ldap.SCOPE_ONELEVEL, - '(keyfingerprint=%s)' % fingerprint, ['uid']) - return Attrs[0][1]['uid'][0] + '(keyfingerprint=%s)' % fingerprint, + ['uid', 'keyfingerprint']) + login = {} + for elem in Attrs: + login[elem[1]['keyFingerPrint'][0]] = elem[1]['uid'][0] + return login ################################################################################