title: How do I get user task list with its process variables in Camunda
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>So I decided to write my own REST service using Camunda Java api. This is what I did -</p>
  
  <pre><code>List&lt;Task&gt; tasks = taskService.createTaskQuery().processDefinitionKey(processDefinitionKey).taskAssignee(assignee).list();
  
   if(tasks != null &amp;&amp; !tasks.isEmpty()){
  
   for(Task task : tasks){
   .....
   .....
   Map&lt;String, Object&gt; variables = taskService.getVariables(task.getId(), variableNames);
   .....
  }}
  </code></pre>
  
  <p>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).</p>
  
  <p>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?</p>
  
  <p>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 &amp; 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?</p>
  
  <p>Thanks in advance for your help.</p>