Browse files

log start index, add back connection cache

  • Loading branch information...
1 parent 0fe57a7 commit f29fe2e3f4b509dbc3a7bc3b97c47851ba84a6c4 Alex Buchanan committed Jul 23, 2010
Showing with 8 additions and 0 deletions.
  1. +1 −0 apps/subscriptions/management/commands/sync_unsubscribe.py
  2. +7 −0 libs/ldaputils.py
View
1 apps/subscriptions/management/commands/sync_unsubscribe.py
@@ -31,6 +31,7 @@ def handle(self, **options):
targets = Subscription.objects.filter(campaign='firefox-home-instructions', active=True).order_by('id')
start = int(vars.get('sync_unsubscribe_index', 0))
+ log.info(start)
end = start + limit
targets = targets[start:end]
count = targets.count()
View
7 libs/ldaputils.py
@@ -8,16 +8,23 @@
log = commonware.log.getLogger('ldap')
+_conn_cache = {}
+
def connect_ldap():
server = '{host}:{port}'.format(**settings.LDAP)
+ if server in _conn_cache:
+ log.debug("using cached LDAP connection")
+ return _conn_cache[server]
+
log.info("Initializing new LDAP connection")
l = ldap.initialize(server)
l.network_timeout = settings.LDAP_TIMEOUT
l.timelimit = settings.LDAP_TIMEOUT
l.timeout = settings.LDAP_TIMEOUT
l.simple_bind_s(settings.LDAP['user'], settings.LDAP['password'])
+ _conn_cache[server] = l
return l

0 comments on commit f29fe2e

Please sign in to comment.