def _get_records(database, keys, function):
    """Return records on database for keys using function."""
    records = dict()
    for k in keys:
        r = function(database, k)
        if r is None:
            records.setdefault(None, []).append(k)
        else:
            kp = r.key.pack()
            if kp not in records:
                records[kp] = r
    return records