Source code for uw.local.grad.db.bulk_unitapp
from .unitapp import UnitApplication
from .unitapp_get import get_app_plan_info, get_app_applicant, get_app_accept_counts, get_app_rating, get_app_info
[docs]def bulk_app_loader(cursor, applids):
"""
This function takes a list of applids and returns the corresponding list of UnitApplication objects with some
information filled it. It is functionally equivalent to just loading UnitApplication in a loop, but faster since it
queries a few times at the beginning instead of each application individually (O(1) vs O(n)).
:param cursor: A database cursor
:param applids: A list of strings corresponding to application identification strings in the form [1234, 1235],
no duplicates will be removed
"""
applids = sorted (applids)
rows = cursor.unitapps_by_ids (appl_ids=applids)
if not rows:
return []
where = "(wa.uw_id, wa.appl_id) IN %(where)s"
vardict = {'where': tuple ((row.uw_id, row.appl_id) for row in rows)}
app_plan_infos = get_app_plan_info (cursor, where, vardict)
app_infos = get_app_info(cursor, where, vardict)
app_ratings = get_app_rating (cursor, where, vardict)
app_applicant = get_app_applicant (cursor, where, vardict)
app_counts = get_app_accept_counts (cursor, where, vardict)
attribute_names = ('plan_info', 'app_info', 'rating', 'applicant', 'counts')
apps = []
for row, api, ai, ar, aa, ac in zip (rows, app_plan_infos, app_infos, app_ratings, app_applicant, app_counts):
ua = UnitApplication (cursor, row)
for k, n in zip (attribute_names, (api, ai, ar, aa, ac)):
ua.__setattr__ (k, n)
apps.append (ua)
return sorted (apps, key=lambda x: x.names)