Ignore:
Timestamp:
Dec 3, 2013, 12:21:44 AM (12 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, stable, stage
Children:
200ae4b
Parents:
d66942f
git-author:
Alex Dehnert <adehnert@…> (12/03/13 00:19:10)
git-committer:
Alex Dehnert <adehnert@…> (12/03/13 00:21:44)
Message:

People lookup: Support large numbers of people

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asadb/forms/models.py

    rd66942f red7ddec  
    226226        fields = ['uid', 'eduPersonAffiliation', 'mitDirStudentYear']
    227227
    228         filters = [ldap.filter.filter_format('(uid=%s)', [u]) for u in usernames]
    229         userfilter = "(|%s)" % (''.join(filters), )
    230         results = con.search_s(dn, ldap.SCOPE_SUBTREE, userfilter, fields)
     228        chunk_size = 100
     229        username_chunks = []
     230        ends = range(chunk_size, len(usernames), chunk_size)
     231        start = 0
     232        for end in ends:
     233            username_chunks.append(usernames[start:end])
     234            start = end
     235        username_chunks.append(usernames[end:])
     236        print username_chunks
     237
     238        results = []
     239        for chunk in username_chunks:
     240            filters = [ldap.filter.filter_format('(uid=%s)', [u]) for u in chunk]
     241            userfilter = "(|%s)" % (''.join(filters), )
     242            batch_results = con.search_s(dn, ldap.SCOPE_SUBTREE, userfilter, fields)
     243            results.extend(batch_results)
    231244
    232245        left = set(usernames)
     
    261274
    262275    def classify_people(self, people):
    263         mit_usernames = set()
     276        mit_usernames = []
    264277        alum_addresses = []
    265278        other_mit_addresses = []
     
    269282            local, at, domain = name.partition('@')
    270283            if domain.lower() == 'mit.edu' or domain == '':
    271                 mit_usernames.add(local)
     284                mit_usernames.append(local)
    272285            elif domain.lower() == 'alum.mit.edu':
    273286                alum_addresses.append((name, None))
Note: See TracChangeset for help on using the changeset viewer.