Проблема с данным кодом он крайне медленный и все из за запроса 
// НОВЫЙ КОД: Получаем ID сотрудников
        query = "for $elem in subs where $elem/org_id = " + project.org_id + " return data($elem/basic_collaborator_id)";
        var employeeIds = XQuery(query);
        var employeeIdsStr = ArrayMerge(employeeIds, "return This", ", ");
        он очень долигий проблема со временем у меня ТОЛЬКО в данном месте оптимизируй данную часть остальное не трогай и дай идеи для оптимизации это код в websoft hcm НЕ JS хотя и похож



var LOG_JOURNAL_NAME = 'sales_status_report_log';

LdsIsServer && EnableLog(LOG_JOURNAL_NAME);

function typeOf(value) {
    var dataType = DataType(value);

    return (dataType === 'date' || dataType === 'object') ? ObjectType(value) : dataType;
}

function map(arr, cb) {
    if (!IsArray(arr)) {
        throw new Error('Передан не массив.');
    }

    if (!typeOf(cb) === 'JsFuncObject') {
        throw new Error('Callback не функция.');
    }

    var newArr = [];

    for (el in arr) {
        newArr.push(
            cb(el)
        );
    }

    return newArr;
}

function getCreatorName(checkpointDoc) {
    var creatorId = checkpointDoc === null ? '' : checkpointDoc.TopElem.doc_info.creation.user_id;
    if (creatorId === '') {
        return '';
    }
    var creatorDoc = tools.open_doc(creatorId);
    if (creatorDoc === undefined || creatorDoc === '' || creatorDoc === null) {
        return '';
    }

    var lastName = creatorDoc.TopElem.lastname;
    var middleName = creatorDoc.TopElem.middlename;
    var firstName = creatorDoc.TopElem.firstname;

    return lastName + ' ' + firstName + ' ' + middleName;
}

var status = Trim(_CRITERIONS[0].value);
var _xquery_qual = '';

var statusesNamesMap = {
    plan: 'Планируется',
    project: 'Проект',
    active: 'В работе',
    close: 'Завершен',
    cancel: 'Отменен',
};

query = "for $elem in projects where $elem/org_id != " + '6698365626107897232' + " and $elem/org_id !='' " + _xquery_qual + "and $elem/status = 'project' or $elem/status = 'plan' " + " return $elem";
var projects = XQuery(query);

query = "for $elem in object_data_types where $elem/code = 'project_checkpoints_reports' return $elem";
var projectCheckpointDataTypeId = OptInt(ArrayOptFirstElem(XQuery(query)).id);

var result = map(
    projects,
    function fn(project) {
        var primaryKey = project.id;
        var clientName = project.org_id.ForeignDispName;
        var projectName = project.name;
        var projectTypeName = project.project_type_id.ForeignDispName;
        var projectStatusName = statusesNamesMap[project.status];

        query = 'for $elem in object_datas where $elem/object_id = ' + project.id + ' and $elem/object_data_type_id = ' + projectCheckpointDataTypeId + " and  $elem/status_id = 'active' order by $elem/create_date descending return $elem";
        var checkpoint = ArrayOptFirstElem(XQuery(query));

        query = "for $elem in projects where $elem/org_id = " + project.org_id + " and $elem/org_id !='' and ($elem/status = 'active' or $elem/status = 'close') " + " return $elem/name, $elem/status";
        var localProjects = XQuery(query)

        var localProjectsActiveStr = ArrayMerge(localProjects, " if (This.status == 'active') return This.name ", ", ");
        var localProjectsCloseStr = ArrayMerge(localProjects, " if (This.status == 'close') return This.name ", ", ");

        var checkpointDate = checkpoint === undefined ? '' : OptDate(checkpoint.create_date);
        var checkpointStatusName = checkpoint === undefined ? '' : statusesNamesMap[checkpoint.status_id.Value];

        var checkpointDoc = tools.get_opened_doc(checkpoint);
        var checkpointComment = checkpointDoc === null ? '' : checkpointDoc.TopElem.custom_elems.ObtainChildByKey('comment_on_status').value;
        var nextCheckpointDate = checkpointDoc === null ? '' : OptDate(checkpointDoc.TopElem.custom_elems.ObtainChildByKey('next_checkpoint_date').value);
        var statusShortComment = checkpointDoc === null ? '' : checkpointDoc.TopElem.custom_elems.ObtainChildByKey('status_short').value;

        checkpointDate = StrDate(checkpointDate, false);
        nextCheckpointDate = StrDate(nextCheckpointDate, false);

        var creatorName = getCreatorName(checkpointDoc);
        
        // НОВЫЙ КОД: Получаем ID сотрудников
        query = "for $elem in subs where $elem/org_id = " + project.org_id + " return data($elem/basic_collaborator_id)";
        var employeeIds = XQuery(query);
        var employeeIdsStr = ArrayMerge(employeeIds, "return This", ", ");
        
        return {
            PrimaryKey: primaryKey,
            clientName: clientName,
            projectName: projectName,
            projectTypeName: projectTypeName,
            projectStatusName: projectStatusName,
            checkpointDate: checkpointDate,
            creatorName: creatorName,
            checkpointStatusName: checkpointStatusName,
            checkpointComment: checkpointComment,
            nextCheckpointDate: nextCheckpointDate,
            statusShortComment: statusShortComment,
            localProjectsActiveStr: localProjectsActiveStr,
            localProjectsCloseStr: localProjectsCloseStr,
            employees: employeeIdsStr // Добавляем строку с ID сотрудников
        }
    }
);

var c_condition = ArrayOptFind(columns, "This.column_title == 'Дата следующей контрольной точки' ")
c_condition.c_conditions[0].value = Date()

return result;