def METHOD_NAME(upstream_artifacts):
    """Return every optional artifact defined in ``upstream_artifacts``, ordered by taskId.
    Args:
        upstream_artifacts: the list of upstream artifact definitions
    Returns:
        dict: list of paths to downloaded artifacts ordered by taskId
    """
    # A given taskId might be defined many times in upstreamArtifacts. Thus, we can't
    # use a dict comprehension
    optional_artifacts_per_task_id = {}
    for artifact_definition in upstream_artifacts:
        if artifact_definition.get("optional", False) is True:
            task_id = artifact_definition["taskId"]
            artifacts_paths = artifact_definition["paths"]
            add_enumerable_item_to_dict(dict_=optional_artifacts_per_task_id, key=task_id, item=artifacts_paths)
    return optional_artifacts_per_task_id