[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] Improve performances of get_logins_from_ldap



Signed-off-by: Luca Falavigna <dktrkranz@debian.org>
---
 dak/queue_report.py |    6 ++++--
 daklib/utils.py     |   10 +++++++---
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/dak/queue_report.py b/dak/queue_report.py
index a8f7410..a2079e8 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 f702db3..377d191 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
 
 ################################################################################
 
-- 
1.7.2.5


Reply to: