Long waiting time on my requests(PHP)

I am receiving long waiting times when GETting data and also when posting data to the api

Response times are between 6-11 seconds and the waiting time i get on post requests is around 2 seconds

I am working with Laravel(PHP version of the api). I read about the opt_fields parameter. I am not sure if I am using it incorectly, since it barely took any time of the request times.

This is how I initially fetch my projects, The get Client funtion retieves the acces token of the user and sets the headers asana-disable of new_user_task_lists and new_project_template

getWorkSpaceID is also a function defined by myself that returns the workspace gid

 public function show()
    {
        return (view('dashboard', [
            'projects' => $this->getClient()->projects->getProjectsForWorkspace($this->getWorkSpaceID(), ['opt_fields' => 'name']),
            'client' => $this->getClient(),
        ]));
    }

In the dashboard I simply work with the data like this(again with the opt_fields parameter)

note: I have taken out some HTML elements since they do not impact this problem and it makes this more readable

@foreach ($projects as $project)
<a class="text-center" href="{{ route('dashboard-project', $project->gid) }}">
 <h1 class="text-2xl font-bold">
               {{ $project->name }}
 </h1>
 
     @foreach ($client->tasks->getTasksForProject($project->gid, ['opt_fields' => 'name']) as $task)
         <p class="mt-1 text-center text-lg font-semibold">
                      {{ $task->name }}
         </p>
                                   
         @foreach ($client->tasks->getSubtasksForTask($task->gid, ['opt_fields' => 'name']) as $subtask)
              <p class="text-sm font-light">
                     {{ $subtask->name }}
              </p>
              @endforeach
       @endforeach

Am I using the opt_fields wrong here? I am receiving no errors. Everything works, I can add tasks aswell. My first thought it was because I am using [‘param’ => ‘field’]
But this is not the case, since it works fine when adding tasks and subtasks

Is there any way to get faster resonse times?

Hi @JordyK , welcome to the forum.

And, welcome the performance issues of the Asana API :smiley:

As I can see in your sample, the whole process took “only” 11 seconds to execute!
So, I suppose you have very few projects / tasks !

Let’s pretend you have 50 projects, with 50 tasks in each.

So, you need to do these calls:

  • getprojects.
  • ( 50 times) getTasksForProject
    plus
  • (50 * 50 times) getSubtasksForTask.

That’s 2500+ calls.

I suggest to use limit:100 parameter, to get more than 10 results on each page.

The asana api can sometimes take up to 5-10 secondes PER CALL !!!
In good period, response time is between 100-250ms. But sometimes, it goes over 10000 ms.

You can imagine that it will take several minutes to execute your dashboard.

You will need to change your approach, with async + progressbar, or offline load, followed by local cache query.

You can try to run multiple calls at once (up to 10) by using the /batch endpoint, it will reduce your load time by 10.

Also, I strongly suggest to query for the opt_field “num_subtasks”. By reading that field, you will know if you need to query “getSubtasksForTask”. If you have 0 num_subtasks in the parent task, you will save lots of queries.

If you run your queries at night during low business hours, the performance will be better.

You are limited to 1500 calls per minute, but if you run your code like this, without parallel query, don’t bother, I think you will never be able to reach that limit.

2 Likes

First of all, thank you for responding. And yes, I only have 3 projects and just a few tasks. Which is why I was shocked it took so long haha.

I looked at the batch endpoint… Do you have a code example of it?

I find the example in the docs to be confusing and did not use it (yet)
because of this

No I don’t, we use it in javascript, but I don’t have PHP samples.

But, in your case… what I really suggest, is to make your app run server-side offline, store the results in your database or local json files, and then, show your dashboard based on these offline data.

If you can see your data with a delay of a few yours, it will be ok. you can schedule your task to run every hour…

Also, when you query subtasks (and maybe stories), I suggest to keep these results locally, and only re-query them if the “modified_at” field has changed in the parent task.

In fact, that’s a quite complex process, more than you initially expected !! :slight_smile:

2 Likes

If you choose to store data locally and update it every hours, take a look at the “search” endpoint.

https://developers.asana.com/docs/search-tasks-in-a-workspace

Use the “modified_at.after” parameter, to query since the last time you run your process…

Hope this helps!

2 Likes

It does, many thanks!

1 Like