

def prefetch(sq, *subqueries):
    if (not subqueries):
        return sq
    fixed_queries = prefetch_add_subquery(sq, instance)
    deps = {
        
    }
    rel_map = {
        
    }
    for prefetch_result in reversed(fixed_queries):
        query_model = prefetch_result.model
        if prefetch_result.fields:
            for rel_model in prefetch_result.rel_models:
                rel_map.setdefault(rel_model, [])
                rel_map[rel_model].append(prefetch_result)
        deps[query_model] = {
            
        }
        id_map = deps[query_model]
        has_relations = bool(rel_map.get(query_model))
        for instance in prefetch_result.query:
            if prefetch_result.fields:
                prefetch_result.store_instance(instance, id_map)
            if has_relations:
                for rel in rel_map[query_model]:
                    rel.populate_instance(instance, deps[rel.model])
    return prefetch_result.query

dataset/ETHPy150Open coleifer/peewee/peewee.py prefetch/VarMisuse@31/45 `subqueries`->`instance`