Reputation: 101
I have a requirement where a user could be assigned thousands (1000 - 5000) tasks, belonging to different process instances (same user task from 1000 - 5000) instances at a given time. I have a custom task list screen where I need to load all the tasks with their basic info (id, name, process instance id etc) and some process variables for each.
First I used the filter/list REST service i.e. engine-rest/filter/{filter-id}/list to get the tasks with the process variables. (I created a filter in Camunda tasklist). But this REST service takes forever to return when there are more than 1000 process instances in question. It took 7-8 mins for about 2000 process instances. Maybe because this service returns a lot of information which I don't need.
So I decided to write my own REST service using Camunda Java api. This is what I did -
List<Task> tasks = taskService.createTaskQuery().processDefinitionKey(processDefinitionKey).taskAssignee(assignee).list();
if(tasks != null && !tasks.isEmpty()){
for(Task task : tasks){
.....
.....
Map<String, Object> variables = taskService.getVariables(task.getId(), variableNames);
.....
}}
This works and is much faster than the filter service. But for about 1000 instances it is taking around 25 secs. (My server is not production grade right now, Tomcat Xms -1gb Xmx - 2gb).
But my concern is that internally is this code hitting the DB 1000 times (for each tasks returned by taskquery) to get the variables? Worse still depending on the number of variables is it querying the DB that many times for each variable? I mean for 5 variables are we hitting the DB 5000 times?
1) If so, is there any way I can improve this service? Like can I write a NativeTaskQuery where I join the act_ru_task, act_ru_process & act_ru_variable tables to get the data I need? Is that the right way? 2) Isn't there any inbuilt caching in Camunda that can help here?
Thanks in advance for your help.
Upvotes: 3
Views: 5735
Reputation: 1
I Get task valid variables from SQL directly by query below :
select
va.PROC_INST_ID_ as ProcessInstanceId
,va.NAME_ as VarName
,va.TEXT_ as VarValue
from [Camunda].[dbo].[ACT_RU_VARIABLE] va
left join [Camunda].[dbo].ACT_RU_EXECUTION ex with (nolock) on ex.ID_ =
va.EXECUTION_ID_
left join [Camunda].[dbo].ACT_RU_TASK ta with (nolock) on ex.ID_ =
ta.EXECUTION_ID_
where ta.ID_ = 'xxxxx-xxxx-xx.....' -- TaskId
and not ex.ID_ is null
group by va.PROC_INST_ID_,va.NAME_,va.TEXT_
Upvotes: -1
Reputation: 11993
You can use a custom query for this. Write your native sql query and add a mybatis mapping. This example explains the concept : https://github.com/camunda-consulting/code/tree/master/snippets/custom-queries
Upvotes: 0