# Path: api/theatrics/connections.py

# 
# Path: api/theatrics/settings.py
# ELASTICSEARCH_INDEX = os.environ.get('ELASTICSEARCH_INDEX', 'theatrics')
# 
# Path: api/theatrics/utils/functional.py
# def containing(value):
#     return lambda container: value in container


import aioes
from funcy import collecting, compact, is_seqcont, pluck
from .connections import elastic
from .settings import ELASTICSEARCH_INDEX
from .utils.functional import containing
    for field, (type_, subfields) in relations.items():
        path = field.split('.')
        field = path[-1]
        items_with_field = _find_items_having_path(item_list, path)

        related_ids = list(compact(pluck(field, items_with_field)))
        if not related_ids:
            continue

        related_items = await fetch_multiple_items(type_, related_ids, subfields)
        related_by_id = {item['id']: item for item in compact(related_items)}

        for item in items_with_field:
            item[field] = related_by_id.get(item[field])

    return item_list


@collecting
def _find_items_having_path(item_list, path):
    assert len(path) > 0

    field, rest = path[0], path[1:]
    if len(path) == 1:
        yield from filter(containing(field), item_list)
        return

    for item in item_list:
        try:
            value = item[field]

# Path: api/theatrics/connections.py

# 
# Path: api/theatrics/settings.py
# ELASTICSEARCH_INDEX = os.environ.get('ELASTICSEARCH_INDEX', 'theatrics')
# 
# Path: api/theatrics/utils/functional.py
# def containing(value):
#     return lambda container: value in container


# Path: api/theatrics/dao.py
import aioes
from funcy import collecting, compact, is_seqcont, pluck
from .connections import elastic
from .settings import ELASTICSEARCH_INDEX
from .utils.functional import containing

    for field, (type_, subfields) in relations.items():
        path = field.split('.')
        field = path[-1]
        items_with_field = _find_items_having_path(item_list, path)

        related_ids = list(compact(pluck(field, items_with_field)))
        if not related_ids:
            continue

        related_items = await fetch_multiple_items(type_, related_ids, subfields)
        related_by_id = {item['id']: item for item in compact(related_items)}

        for item in items_with_field:
            item[field] = related_by_id.get(item[field])

    return item_list


@collecting
def _find_items_having_path(item_list, path):
    assert len(path) > 0

    field, rest = path[0], path[1:]
    if len(path) == 1:
        yield from filter(containing(field), item_list)
        return

    for item in item_list:
        try:
            value = item[field]

        except: