Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(flow):improve list API rt #1383

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2024 OceanBase.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


alter table `flow_instance` add index `flow_instance_parent_ins_id`(`parent_instance_id`);

alter table `flow_instance_node_task` add index `flow_instance_node_task_flow_instance_id`(`flow_instance_id`);

alter table `flow_instance` add index `flow_instance_parent_oid_ct_id`(`organization_id`,`create_time`,`id`);

CREATE or replace VIEW `list_flow_instance_view` AS
PeachThinking marked this conversation as resolved.
Show resolved Hide resolved
select
`flow_instance`.`id` AS `id`,
`flow_instance`.`create_time` AS `create_time`,
`flow_instance`.`update_time` AS `update_time`,
`flow_instance`.`name` AS `name`,
`flow_instance`.`flow_config_id` AS `flow_config_id`,
`flow_instance`.`creator_id` AS `creator_id`,
`flow_instance`.`organization_id` AS `organization_id`,
`flow_instance`.`process_definition_id` AS `process_definition_id`,
`flow_instance`.`process_instance_id` AS `process_instance_id`,
`flow_instance`.`status` AS `status`,
`flow_instance`.`flow_config_snapshot_xml` AS `flow_config_snapshot_xml`,
`flow_instance`.`description` AS `description`,
`flow_instance`.`parent_instance_id` AS `parent_instance_id`,
`flow_instance`.`project_id` AS `project_id`,
`flow_instance_node_task`.`task_type` AS `task_type`
from
(
`flow_instance` join `flow_instance_node_task` on ( `flow_instance`.`id` = `flow_instance_node_task`.`flow_instance_id`)
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.oceanbase.odc.config.jpa.OdcJpaRepository;
import com.oceanbase.odc.core.shared.constant.FlowStatus;
import com.oceanbase.odc.core.shared.constant.TaskType;

Expand All @@ -39,7 +39,7 @@
* @see org.springframework.data.jpa.repository.JpaRepository
*/
public interface FlowInstanceRepository
extends JpaRepository<FlowInstanceEntity, Long>, JpaSpecificationExecutor<FlowInstanceEntity> {
extends OdcJpaRepository<FlowInstanceEntity, Long>, JpaSpecificationExecutor<FlowInstanceEntity> {

List<FlowInstanceEntity> findByIdIn(Collection<Long> ids);

Expand Down Expand Up @@ -82,6 +82,12 @@ int updateProcessDefinitionIdById(@Param("flowInstanceId") Long flowInstanceId,

List<FlowInstanceEntity> findByParentInstanceId(Long parentInstanceId);

List<FlowInstanceEntity> findByParentInstanceIdIn(Collection<Long> parentInstanceId);
yizhouxw marked this conversation as resolved.
Show resolved Hide resolved

default List<FlowInstanceEntity> partitionFindByParentInstanceIdIn(Collection<Long> parentInstanceId) {
return partitionFind(parentInstanceId, 200, this::findByParentInstanceIdIn);
}

@Query(value = "select a.parent_instance_id from flow_instance a left join flow_instance_node_task b on a.id = b.flow_instance_id"
+ " where a.id=:id and task_task_id is not null and b.task_type='ALTER_SCHEDULE' LIMIT 1",
nativeQuery = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,13 @@ private FlowInstanceMapper generateMapper(@NonNull Collection<Long> flowInstance
.collect(Collectors.groupingBy(ServiceTaskInstanceEntity::getFlowInstanceId,
Collectors.mapping(ServiceTaskInstanceEntity::getStrategy, Collectors.toList())));

Map<Long, List<FlowInstanceEntity>> parentInstanceIdMap = flowInstanceRepository
.partitionFindByParentInstanceIdIn(
flowInstanceIds)
.stream().collect(Collectors.groupingBy(FlowInstanceEntity::getParentInstanceId));

Map<Long, Boolean> flowInstanceId2Rollbackable = flowInstanceIds.stream().collect(Collectors
.toMap(Function.identity(), id -> flowInstanceRepository.findByParentInstanceId(id).size() == 0));
.toMap(Function.identity(), id -> CollectionUtils.isEmpty(parentInstanceIdMap.get(id))));

/**
* In order to improve the interface efficiency, it is necessary to find out the task entity
Expand Down