cancel
Showing results for 
Search instead for 
Did you mean: 

Extremely slow TaskQuery execution with logical operators and paging

xvelez
Champ in-the-making
Champ in-the-making
Hello.

We have a 30,000 task activiti-generated DB. We're trying to fix some performance issues when querying to obtain unassigned tasks with a number of different process variables with paging.

So I modified our current TaskQuery method from this (which already includes paging but not iterating over different process variables):


protected List<Task> findUnassignedTasks(TASK taskKey, VARIABLE processVariable, int page, int size) {
        int offset = page * size;
        return buildBaseTaskQuery().
                processVariableValueEquals(processVariable.getKey(), processVariable.getValue()).
                includeProcessVariables().
                taskUnassigned().
                taskDefinitionKey(taskKey.getKey()).
                listPage(offset, size);
    }

//<TASK extends TaskKey, VARIABLE extends ProcessVariable>


To this:

protected List<Task> findUnassignedTasks(TASK taskKey, VARIABLE[] processVariables, int page, int size) {
        int offset = page * size;
        TaskQuery taskQuery = buildBaseTaskQuery().or();
        for (int i = 0; i < processVariables.length; i++) {
            taskQuery.processVariableValueEquals(processVariables.getKey(), processVariables.getValue());
        }
        taskQuery.endOr();

        return taskQuery.
                includeProcessVariables().
                taskUnassigned().
                taskDefinitionKey(taskKey.getKey()).
                listPage(offset, size);
    }


But this query takes so long that it goes on timeout… What can I do to speed things up? Am I missing something?

I have tried removing the process variable inclusion but we need it in order to obtain the assignee and other information. Is there a way I could request specific process variables?

1 REPLY 1

jbarrez
Star Contributor
Star Contributor
The problem is the includeVariables. That is a very costly join that is happening + some post processing.
I think that in this case, it would be better to use a native query that does directly what you want to do.