Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ungreat committed Jan 12, 2024
1 parent f2589c5 commit 31c2d13
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
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 VIEW `list_flow_instance_view2` AS
select
`odc_metadb3`.`flow_instance`.`id` AS `id`,
`odc_metadb3`.`flow_instance`.`create_time` AS `create_time`,
`odc_metadb3`.`flow_instance`.`update_time` AS `update_time`,
`odc_metadb3`.`flow_instance`.`name` AS `name`,
`odc_metadb3`.`flow_instance`.`flow_config_id` AS `flow_config_id`,
`odc_metadb3`.`flow_instance`.`creator_id` AS `creator_id`,
`odc_metadb3`.`flow_instance`.`organization_id` AS `organization_id`,
`odc_metadb3`.`flow_instance`.`process_definition_id` AS `process_definition_id`,
`odc_metadb3`.`flow_instance`.`process_instance_id` AS `process_instance_id`,
`odc_metadb3`.`flow_instance`.`status` AS `status`,
`odc_metadb3`.`flow_instance`.`flow_config_snapshot_xml` AS `flow_config_snapshot_xml`,
`odc_metadb3`.`flow_instance`.`description` AS `description`,
`odc_metadb3`.`flow_instance`.`parent_instance_id` AS `parent_instance_id`,
`odc_metadb3`.`flow_instance`.`project_id` AS `project_id`,
`odc_metadb3`.`flow_instance_node_task`.`task_type` AS `task_type`
from
(
`odc_metadb3`.`flow_instance` join `odc_metadb3`.`flow_instance_node_task` on ( `odc_metadb3`.`flow_instance`.`id` = `odc_metadb3`.`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);

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

0 comments on commit 31c2d13

Please sign in to comment.