AnsweredAssumed Answered

TaskQuery slow with many tasks

Question asked by pcsquirrel on Jun 15, 2011
Latest reply on Aug 24, 2011 by frederikheremans1
Hi,

first off all CONGRATULATION - ACTIVITI is really a awesome framework.

I´m just implementing an application using Activiti and fiddling for better performance. While doing that I discoverd that Taskquery is rather slow if I have many Tasks. Let me explain:

I have 100 Tasks for group "management".
I want to list them all and do a TaskQuery:


List<Task> tasks = tasksvc.createTaskQuery().taskCandidateGroup("management").list();

This query issues 1+N SELECT-Statements against the database which is quite slow.

1.

select distinct T.* from ACT_RU_TASK T inner join ACT_RU_IDENTITYLINK I on I.TASK_ID_ = T.ID_ WHERE T.ASSIGNEE_ is null and I.TYPE_ = 'candidate' and ( I.GROUP_ID_ IN ( ? ) )
Parameters: management(String)

N times for each Task returned by previos Query

select * from ACT_HI_TASKINST where ID_ = ?
Parameters: 2390(String)


As far as I have seen this is caused by the function "setTaskDefinitionKey" in class TaskEntitiy


  public void setTaskDefinitionKey(String taskDefinitionKey) {
    this.taskDefinitionKey = taskDefinitionKey;
   
    CommandContext commandContext = Context.getCommandContext();
    if(commandContext != null) {
      int historyLevel = Context.getProcessEngineConfiguration().getHistoryLevel();
      if (historyLevel >= ProcessEngineConfigurationImpl.HISTORYLEVEL_AUDIT) {
        HistoricTaskInstanceEntity historicTaskInstance = commandContext.getDbSqlSession().selectById(HistoricTaskInstanceEntity.class, id);
        if (historicTaskInstance!=null) {
          historicTaskInstance.setTaskDefinitionKey(this.taskDefinitionKey);
        }
      }
    }
  }

I have HistoryLevel set to "Audit"  to track variable changes. But what is the sense of above code? Variable "historicTaskInstance" isn´t used in this function.
(or is there some MyIbatis magic?).

Is there a way to improve my query without the N additional SELECT statements?

Kind regards
Philipp Eichhorn

Outcomes