async def prefetch(sq, *subqueries):
if not subqueries:<EOL><INDENT>result = await execute(sq)<EOL>return result<EOL><DEDENT>fixed_queries = peewee.prefetch_add_subquery(sq, subqueries)<EOL>deps = {}<EOL>rel_map = {}<EOL>for pq in reversed(fixed_queries):<EOL><INDENT>query_model = pq.model<EOL>if pq.fields:<EOL><INDENT>for rel_model in pq.rel_models:<EOL><INDENT>rel_map.setdefault(rel_model, [])<EOL>rel_map[rel_model].append(pq)<EOL><DEDENT><DEDENT>deps[query_model] = {}<EOL>id_map = deps[query_model]<EOL>has_relations = bool(rel_map.get(query_model))<EOL>result = await execute(pq.query)<EOL>for instance in result:<EOL><INDENT>if pq.fields:<EOL><INDENT>pq.store_instance(instance, id_map)<EOL><DEDENT>if has_relations:<EOL><INDENT>for rel in rel_map[query_model]:<EOL><INDENT>rel.populate_instance(instance, deps[rel.model])<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return result<EOL>
Asynchronous version of the `prefetch()` from peewee.