CreateTaskQuery is taking long time (3 secs)

I have written a code to find the current active user task. The problem is that it takes 3 seconds to execute. There is no load on system and I am just trying it for one execution. Also there is ony one active task for my case. Any idea why the below code is taking time

Task curentUserTask = taskService.createTaskQuery().initializeFormKeys().active()
.processInstanceId(String.valueOf(executionId))
.orderByTaskCreateTime()
.asc().singleResult();

I have also tried removing .orderByTaskCreateTime().asc() just to eliminate if the sorting is causing slowness, though it doesn’t make any difference

Hello my friend!

I’m not sure about this, but I imagine that the fact that this call of yours scans all deployed processes, and all activities, can generate some kind of slowness.

If you set in your call, in addition to the processInstanceId, a single processDefinition to make your query… does the time decrease?

William Robert Alves

Thanks @WilliamR.Alves for the suggestion. I also tried passing processDefinition but it didn’t help. Still it’s taking close to 3 seconds. Also tried upgrading to 7.19 but that also doesn’t help

BTW, this is a duplicate thread to TaskService query very slow even for small amount of data