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/mnt 24335 performance issue wf tests with unit tests preview #4638

Open
wants to merge 17 commits into
base: 7.11.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ on:
push:
branches:
- 7.11.x
- fix/MNT-24335-performance_issue_WF_tests_withUnitTests
pull_request:
branches:
- 7.11.x
- fix/MNT-24335-performance_issue_WF_tests_withUnitTests
# Allows to run this workflow manually from the Actions tab
workflow_dispatch:
concurrency:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,8 @@ public Object execute(CommandContext commandContext) {
parameterMap.put("resultType", "LIST_PAGE");
parameterMap.put("firstResult", firstResult);
parameterMap.put("maxResults", maxResults);
if (StringUtils.isNotBlank(Objects.toString(parameterMap.get("orderBy")))) {
parameterMap.put("orderByColumns", "RES." + parameterMap.get("orderBy"));
} else {
parameterMap.put("orderByColumns", "RES.ID_ asc");
}
Object orderBy = parameterMap.getOrDefault("orderBy", "ID_ asc");
parameterMap.put("orderByColumns", "RES." + orderBy);

int firstRow = firstResult + 1;
parameterMap.put("firstRow", firstRow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import org.activiti.engine.DynamicBpmnConstants;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricTaskInstanceQuery;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.interceptor.CommandExecutor;
import org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntity;
import org.activiti.engine.impl.variable.VariableTypes;
import org.activiti.engine.query.QueryProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -43,6 +45,11 @@ public class HistoricTaskInstanceQueryImpl extends AbstractVariableQueryImpl<His

private static final Logger log = LoggerFactory.getLogger(HistoricTaskInstanceQueryImpl.class);

private static final HistoricTaskInstanceQueryProperty START_QUERY_PROPERTY_WITHOUT_ALIAS =
new HistoricTaskInstanceQueryProperty(
removeAliasFromPropertyName(HistoricTaskInstanceQueryProperty.START.getName())
);

protected String processDefinitionId;
protected String processDefinitionKey;
protected String processDefinitionKeyLike;
Expand Down Expand Up @@ -1217,8 +1224,25 @@ public HistoricTaskInstanceQueryImpl orderByHistoricActivityInstanceStartTime()
return this;
}

private boolean isPostgresqlDatabase() {
return ProcessEngineConfigurationImpl.DATABASE_TYPE_POSTGRES.equals(databaseType);
}
private boolean isH2Database() {
return ProcessEngineConfigurationImpl.DATABASE_TYPE_H2.equals(databaseType);
}

private boolean isMysqlDatabase() {
return ProcessEngineConfigurationImpl.DATABASE_TYPE_MYSQL.equals(databaseType);
}

public HistoricTaskInstanceQuery orderByHistoricTaskInstanceStartTime() {
orderBy(HistoricTaskInstanceQueryProperty.START);
QueryProperty queryProperty;
if( isPostgresqlDatabase() || isH2Database() || isMysqlDatabase() ) {
queryProperty = START_QUERY_PROPERTY_WITHOUT_ALIAS;
} else {
queryProperty = HistoricTaskInstanceQueryProperty.START;
}
orderBy(queryProperty);
return this;
}

Expand Down Expand Up @@ -1299,6 +1323,14 @@ public String getMssqlOrDB2OrderBy() {
return specialOrderBy;
}

public static String removeAliasFromPropertyName(String propertyName) {
String specialPropertyName = propertyName;
if (specialPropertyName != null && specialPropertyName.length() > 0) {
specialPropertyName = specialPropertyName.replace("RES.", "");
}
return specialPropertyName;
}

public List<String> getCandidateGroups() {
if (candidateGroup != null) {
List<String> candidateGroupList = new ArrayList<String>(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@

<select id="selectHistoricTaskInstanceCountByQueryCriteria" parameterType="org.activiti.engine.impl.HistoricTaskInstanceQueryImpl" resultType="long">
select count(DISTINCT RES.ID_)
<include refid="selectHistoricTaskInstancesByQueryCriteriaSql"/>
<include refid="selectHistoricTaskInstancesByQueryCriteriaSql">
<property name="selectCount" value="yes"/>
</include>
</select>

<sql id="selectHistoricTaskInstancesByQueryCriteriaSql">
Expand Down Expand Up @@ -358,8 +360,12 @@
</sql>

<sql id="commonSelectHistoricTaskInstancesByQueryCriteriaSql">
<if test="candidateUser != null || candidateGroups != null || involvedGroups != null">
inner join ${prefix}ACT_HI_IDENTITYLINK HI on HI.TASK_ID_ = RES.ID_
<if test="candidateUser != null || candidateGroups != null || involvedGroups != null || involvedUser != null">
<choose>
<when test="involvedGroups != null || involvedUser != null">left</when>
<otherwise>inner</otherwise>
</choose>
join ${prefix}ACT_HI_IDENTITYLINK HI on HI.TASK_ID_ = RES.ID_
</if>
<if test="processFinished || processUnfinished || processInstanceBusinessKey != null || processInstanceBusinessKeyLike != null || processInstanceBusinessKeyLikeIgnoreCase != null">
inner join ${prefix}ACT_HI_PROCINST HPI ON RES.PROC_INST_ID_ = HPI.ID_
Expand All @@ -381,9 +387,9 @@
</choose>
</foreach>
<foreach collection="orQueryObjects" index="orIndex" item="orQueryObject">
<if test="orQueryObject.candidateUser != null || orQueryObject.candidateGroups != null || orQueryObject.involvedGroups != null">
<if test="orQueryObject.candidateUser != null || orQueryObject.candidateGroups != null || orQueryObject.involvedGroups != null || orQueryObject.involvedUser != null">
<choose>
<when test="orQueryObject.involvedGroups != null">left</when>
<when test="orQueryObject.involvedGroups != null || orQueryObject.involvedUser != null">left</when>
<otherwise>inner</otherwise>
</choose>
join ${prefix}ACT_HI_IDENTITYLINK HI_OR${orIndex} on HI_OR${orIndex}.TASK_ID_ = RES.ID_
Expand Down Expand Up @@ -635,14 +641,29 @@
</if>
)
</if>
<if test="involvedUser != null">
and
(
exists(select LINK.USER_ID_ from ${prefix}ACT_HI_IDENTITYLINK LINK where USER_ID_ = #{involvedUser} and LINK.TASK_ID_ = RES.ID_)
or RES.ASSIGNEE_ = #{involvedUser}
or RES.OWNER_ = #{involvedUser}
)
</if>
<choose>
<when test="'${selectCount}' == 'yes'">
<if test="involvedUser != null">
and
(
exists(select LINK.USER_ID_ from ${prefix}ACT_HI_IDENTITYLINK LINK where USER_ID_ = #{involvedUser} and LINK.TASK_ID_ = RES.ID_)
or RES.ASSIGNEE_ = #{involvedUser}
or RES.OWNER_ = #{involvedUser}
)
</if>
</when>
<otherwise>
<if test="involvedUser != null">
and
(
HI.USER_ID_ = #{involvedUser}
or RES.ASSIGNEE_ = #{involvedUser}
or RES.OWNER_ = #{involvedUser}
)
</if>
</otherwise>
</choose>

<if test="involvedGroups != null &amp;&amp; involvedGroups.size() &gt; 0">
and
(
Expand Down Expand Up @@ -949,24 +970,31 @@
</if>
))
</if>
<if test="orQueryObject.involvedUser != null">
or
(
exists(select LINK.USER_ID_ from ${prefix}ACT_HI_IDENTITYLINK LINK where USER_ID_ = #{orQueryObject.involvedUser} and LINK.TASK_ID_ = RES.ID_)
or RES.ASSIGNEE_ = #{orQueryObject.involvedUser}
or RES.OWNER_ = #{orQueryObject.involvedUser}
)
</if>
<choose>
<when test="'${selectCount}' == 'yes'">
<if test="orQueryObject.involvedUser != null">
or
(
exists(select LINK.USER_ID_ from ${prefix}ACT_HI_IDENTITYLINK LINK where USER_ID_ = #{orQueryObject.involvedUser} and LINK.TASK_ID_ = RES.ID_)
or RES.ASSIGNEE_ = #{orQueryObject.involvedUser}
or RES.OWNER_ = #{orQueryObject.involvedUser}
)
</if>
</when>
<otherwise>
<if test="orQueryObject.involvedUser != null">
or
(
HI_OR${orIndex}.USER_ID_ = #{orQueryObject.involvedUser}
or RES.ASSIGNEE_ = #{orQueryObject.involvedUser}
or RES.OWNER_ = #{orQueryObject.involvedUser}
)
</if>
</otherwise>
</choose>

<if test="orQueryObject.involvedGroups != null &amp;&amp; orQueryObject.involvedGroups.size() &gt; 0">
or
(
HI_OR${orIndex}.TYPE_ = 'participant'
and
HI_OR${orIndex}.GROUP_ID_ IN
<foreach item="group" index="index" collection="orQueryObject.involvedGroups" open="(" separator="," close=")">
#{group}
</foreach>
)
or ( <include refid="orQueryObject_involvedGroups"/> )
</if>
<foreach item="queryVar" collection="orQueryObject.queryVariableValues" index="index">
or
Expand Down Expand Up @@ -1042,10 +1070,37 @@
</trim>
</foreach>
</trim>
<!-- we're using UNION for every situation that doesn't COUNT -->
<if test="'${selectCount}' != 'yes'">
<if test="orQueryObject.involvedGroups != null &amp;&amp; orQueryObject.involvedGroups.size() &gt; 0">
UNION
select distinct RES.*
from ACT_HI_TASKINST RES
left join ACT_HI_IDENTITYLINK HI_OR${orIndex} on HI_OR${orIndex}.TASK_ID_ = RES.ID_
WHERE
<trim prefixOverrides="AND">
<if test="unfinished">
AND RES.END_TIME_ is null
</if>
<if test="finished">
AND RES.END_TIME_ is not null
</if>
</trim>
AND ( <include refid="orQueryObject_involvedGroups"/> )
</if>
</if>
</foreach>
</where>
</sql>

<sql id="orQueryObject_involvedGroups">
HI_OR${orIndex}.TYPE_ = 'participant'
and HI_OR${orIndex}.GROUP_ID_ IN
<foreach item="group" index="index" collection="orQueryObject.involvedGroups" open="(" separator="," close=")">
#{group}
</foreach>
</sql>

<sql id="executionVariableOperator">
<choose>
<when test="queryVar.operator.equals('EQUALS')">=</when>
Expand Down