Ignore:
Timestamp:
11 Jan 2007, 22:03:22 (18 years ago)
Author:
joachim
Message:

improve searchspeed (in custom)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/skins/waeup_student/search_students.py

    r1192 r1278  
    1212list Students for ClearanceOfficers
    1313"""
     14import logging
     15logger = logging.getLogger('Search.Timer')
     16from DateTime import DateTime
     17#
     18#with_timer = True
     19with_timer = False
     20#
    1421request = REQUEST
    1522form = request.form
    1623fget = form.get
    17 #wftool = context.portal_workflow
    1824mtool = context.portal_membership
    1925member = mtool.getAuthenticatedMember()
    2026is_anon = mtool.isAnonymousUser()
    21 #roles = member.getRolesInContext(context)
    2227lt = context.portal_layouts
    23 #pr = context.portal_registration
    2428path_info = request.get('PATH_INFO').split('/')
    2529
     
    2731if is_anon:
    2832    allowed = False
    29 
    3033try:
    3134    from Products.AdvancedQuery import Eq, Between, Le,In
     
    5760user_info['departments'] = []
    5861user_info['faculties'] = []
    59 #from Products.zdb import set_trace
    60 #set_trace()
    6162co_view = False
     63faculties =  fget('faculties')
     64departments = fget('departments')
     65dep_str = fac_str = ''
    6266if "ClearanceOfficers" in member.getGroups():
    6367    state = "clearance_requested"
    6468    only_review = False
    6569    co_view = True
    66     query = In('portal_type',('Faculty',)) &\
    67              In('localUsersWithRoles', ("user:%s" % member,))
    68     res = evalAdvancedQuery(query)
    69     faculties = []
    70     if res:
    71         faculties = [f.getId for f in res]
    72     user_info['faculties'] = faculties
    73     query = In('portal_type',('Department',)) &\
    74              In('localUsersWithRoles', ("user:%s" % member,))
    75     res = evalAdvancedQuery(query)
    76     departments = []
    77     if res:
    78         departments = [f.getId for f in res]
    79     user_info['departments'] = departments
     70    if faculties or departments:
     71        #from Products.zdb import set_trace;set_trace()
     72        if faculties:
     73            fac_str = faculties
     74            faculties = faculties.split()
     75        if departments:
     76            dep_str = departments
     77            departments = departments.split()
     78    else:
     79        query = In('portal_type',('Faculty',)) &\
     80                 In('localUsersWithRoles', ("user:%s" % member,))
     81        res = evalAdvancedQuery(query)
     82        faculties = []
     83        if res:
     84            faculties = [f.getId for f in res]
     85        user_info['faculties'] = faculties
     86        fac_str = " ".join(faculties)
     87        query = In('portal_type',('Department',)) &\
     88                 In('localUsersWithRoles', ("user:%s" % member,))
     89        res = evalAdvancedQuery(query)
     90        departments = []
     91        if res:
     92            departments = [f.getId for f in res]
     93        user_info['departments'] = departments
     94        dep_str = " ".join(departments)
    8095default = {'search_mode': 'student_id',
    8196        'review_state': state,
     
    89104                      layout_mode='edit',
    90105                      formaction="search_students",
     106                      faculties = fac_str,
     107                      departments = dep_str,
    91108                      commit = False,
    92109                      )
     
    140157        res = context.students_catalog(department=term.strip())
    141158        search_set = [r.id for r in res]
     159    elif what == "matric_no":
     160        res = context.students_catalog(matric_no=term.strip())
     161        search_set = [r.id for r in res]
    142162    elif what in st_queries:
    143163        if what == "jamb_reg_no":
    144164            pt = ('StudentApplication',)
    145             st = "%s" % term.strip().lower()
    146         elif what == "matric_no":
    147             pt = ('StudentClearance',)
    148165            st = "%s" % term.strip().lower()
    149166        elif what == "name":
     
    156173                pl = r.getPath().split('/')
    157174                search_set.append(pl[pl.index('students') + 1])
    158 elif co_view:
    159     #from Products.zdb import set_trace
    160     #set_trace()
     175if only_review or with_review or co_view:
     176    if with_timer:
     177        start = DateTime().timeTime()
     178        logger.info('"%s","start 100"' % member)
     179    query = Eq('review_state',state)
     180    review_res = evalAdvancedQuery(query)
     181    if with_timer:
     182        end = DateTime().timeTime()
     183        logger.info('"%s","searchtime","%6.2f"' % (member,end-start))
     184if co_view:
    161185    only_review = False
     186    with_review = True
     187    if with_timer:
     188        start = DateTime().timeTime()
     189        logger.info('"%s","start 200"' % member)
    162190    query = In('faculty',faculties) | In('department',departments)
    163191    res = aq_students(query)
     192    if with_timer:
     193        end = DateTime().timeTime()
     194        logger.info('"%s","searchtime","%6.2f"' % (member,end-start))
     195    start = DateTime().timeTime()
    164196    search_set = [r.id for r in res]
    165 if only_review or with_review:
    166     query = Eq('review_state',state)
    167     review_res = evalAdvancedQuery(query)
    168 review_set = []
     197    if with_timer:
     198        end = DateTime().timeTime()
     199        logger.info('"%s","searchtime","%6.2f"' % (member,end-start))
     200if with_timer:
     201    logger.info('"%s","start 300"' % member)
     202    start = DateTime().timeTime()
    169203if review_res:
    170     for r in review_res:
    171         if r.portal_type == "StudentAccommodation":
    172             start = r.getPath().find('/students/') + 10
    173             review_set.append(r.getPath()[start:start+7])
    174         else:
    175             review_set.append(r.getId)
    176 #set_trace()
     204    review_set = [r.getId for r in review_res]
     205if with_timer:
     206    end = DateTime().timeTime()
     207    logger.info('"%s","searchtime","%6.2f"' % (member,end-start))
     208    logger.info('"%s","start 400"' % member)
     209    start = DateTime().timeTime()
    177210if only_review:
    178211    all = review_set
     
    184217else:
    185218    all = search_set
     219if with_timer:
     220    end = DateTime().timeTime()
     221    logger.info('"%s","searchtime","%6.2f"' % (member,end-start))
    186222items = all[:500]
    187223students = []
     224if with_timer:
     225    logger.info('"%s","start 500"' % member)
     226    start = DateTime().timeTime()
    188227if items:
    189228    for item in items:
     
    193232        for field in stcat.schema() + stcat.indexes():
    194233            info[field] = getattr(record, field)
    195 ##        if "ClearanceOfficers" in member.getGroups():
    196 ##            co_view = True
    197 ##            res = context.portal_catalog(portal_type='Student', id = item)
    198 ##            if len(res) != 1:
    199 ##                continue
    200 ##            droles = member.getRolesInContext(res[0].getObject())
    201 ##            info['review_state'] = res[0].review_state
    202 ##            if "ClearanceOfficer" in droles:
    203 ##                students.append(info)
    204234        else:
    205235            students.append(info)
     236    if with_timer:
     237        end = DateTime().timeTime()
     238        logger.info('"%s","searchtime","%6.2f"' % (member,end-start))
    206239
    207240    return context.search_students_form(rendered = rend,
Note: See TracChangeset for help on using the changeset viewer.