'Returns a dictionary mapping Location -> item data, populated with json data
for all descendents of items up to the specified depth.
(0 = no descendents, 1 = children, 2 = grandchildren, etc)
If depth is None, will load all the children.
This will make a number of queries that is linear in the depth.'

def _cache_children(self, course_key, items, depth=0):

    data = {}
    to_process = list(items)
    course_key = self.fill_in_run(course_key)
    parent_cache = self._get_parent_cache(self.get_branch_setting())
    while ((to_process and (depth is None)) or (depth >= 0)):
        children = []
        for item in to_process:
            self._clean_item_data(item)
            item_location = Location._from_deprecated_son(item['location'], course_key.run)
            item_children = item.get('definition', {}).get('children', [])
            children.extend(item_children)
            for item_child in item_children:
                parent_cache.set(item_child, item_location)
            data[item_location] = item
        if (depth == 0):
            break
        to_process = []
        if children:
            to_process = self._query_children_for_cache_children(course_key, children)
        if (depth is not None):
            depth -= 1
    return data
