podio-community / podio-php

PHP Client for the Podio API.
https://podio-community.github.io/podio-php/
MIT License
153 stars 173 forks source link

get_references produces Podio 504 Error #249

Closed manuelKruesi closed 1 month ago

manuelKruesi commented 1 month ago

Hello there and thanks in Advance for your help!

I am using $references = \PodioItem::get_references($this->client, $item_id ); to retrieve all linked items for a specific item. I am observing a strange behaviour i cannot explain: Sometimes, this operation is extremly slow, mostly on my first few calls of the day. I am not using any caching, but it seems after i used this call a few times, it gets faster, so i suppose there is some sort of caching on podios side. Heres a short outtake from my logs:

Podio Log: Time:08-19-2024 06:52:13.303300; Method: getItem  Args: item_id: xxx; App ID: xxx

Podio Log: Time:08-19-2024 06:52:13.601900; Method: getReferencedItemsByAppId  Args: app_id: xxx ;item_id: xxx;

Podio Log: Time:08-19-2024 06:52:17.894200; Method: getReferencedItemsByAppId  Args: app_id: xxx ;item_id: xxx;

Status: 504 Message: PodioUnavailableError
#0 xxx.php(39): Podio\ApiClient\ApiClient->getReferencedItemsByAppId()

As we see, it is very slow (almost 4 seconds for the first call, fails on the 2nd (note: the time is logged before the actual call))

now when i reload after the error it looks more like this:

Podio Log: Time:08-19-2024 06:54:42.887100; Method: getReferencedItemsByAppId  Args: app_id: xxx;item_id: xxx;

Podio Log: Time:08-19-2024 06:54:43.017800; Method: getReferencedItemsByAppId  Args: app_id: xxx;item_id: xxx;

Podio Log: Time:08-19-2024 06:54:43.826300; Method: getReferencedItemsByAppId  Args: app_id: xxx;item_id: xxx;

Podio Log: Time:08-19-2024 06:54:51.925900; Method: getItem  Args: item_id: xxx; App ID: xxx

While still slow, it is now much faster (0.8s)

Has anyone had this issue before or knows a way to work around this? Thanks a lot for your help!

manuelKruesi commented 1 month ago

I just noticed that there were way more Items attached than i had anticipated and therefor the slow response is understandable. If you encounter a similar problem: Try using another approach to get the referenced Items than the get_references, since this is borderline useless. Build your own foreach or filter function to retrieve less Items.