Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too many api calls when trying to get cards moved from a list to another #24

Open
seblegall opened this issue Apr 5, 2016 · 3 comments

Comments

@seblegall
Copy link

Hi,

Here is a use case I needed to implement for generating BurnDown Chart using Trello actions.

Here is my algorithme :

  1. Get board
  2. Get lists "from and "to"
  3. Get all cards in the "to" list.
  4. Foreach cards of this list, get all actions of the card.
  5. Foreach action, check the type of action (update) and check from wich list and to wich list the card has been moved (in order to check if the card is coming from my "from" list)
  6. If the card is coming from the "from" list, get the name and preg_match ([0-9]*)

The global goal is to find all cards which have been moved from a list 1 to a list 2 during an interval of 2 dates.

Unfortunately, it seems that Trello API does not provide a web service to get all the moved card from or to a selected list.

Anyway, with your php-trello-api wrapper, it seems that the refresh method is called each time an object is instantiated... resulting an API call for each instantiation...

In my example it result 1865 API Calls...

Here is the Blackfire profile : https://blackfire.io/profiles/dff19c00-03a0-41b8-99f7-d36dcf542f3e/graph?settings%5Bdimension%5D=wt&settings%5Bdisplay%5D=landscape&settings%5BtabPane%5D=nodes&selected=&callname=main()

@seblegall seblegall changed the title Too much api calls when trying to get cards moved from a list to another Too many api calls when trying to get cards moved from a list to another Apr 5, 2016
@cdaguerre
Copy link
Owner

Hi @seblegall
As a quick solution: You could extend the models (Card, for instance) and override the __construct method to not refresh every object on load, but you would have to make sure you get all the data you need later on, ie. by manually calling $card->refresh() if you need..

namespace Your\Namespace\Model;

use Trello\Model\Card as BaseCard;
use Trello\ClientInterface;

class Card extends BaseCard
{
    /**
     * {@inheritdoc}
     */
    public function __construct(ClientInterface $client, $id = null)
    {
        $this->client = $client;
        $this->api    = $client->api($this->apiName);

        $this->fields = $this->api->getFields();

        if ($id) {
            $this->id = $id;
            // Comment the line below to avoid unnecessary api calls
            // $this->refresh();
        }
    }
}

You'd also have to extend the Manager to use your custom classes and use your own Manager.

namespace Your\Namespace;

use Trello\Manager as BaseManager;
use Your\Namespace\Model\Card;

class Manager extends BaseManager
{
    /**
     * {@inheritdoc}
     */
    public function getCard($id = null)
    {
        return new Card($this->client, $id);
    }
}

Hope that helps.
If you want, you could make a PR to make automatic refreshing configurable through the manager!

@cdaguerre
Copy link
Owner

@seblegall By the way, having a look at your blackfire profile it seems you would need to override Card, Cardlist and Action...

@seblegall
Copy link
Author

@cdaguerre Yes, I will try that. Another way to improve api calls I implemented is to call the api directly.

Instead of

$lists = $board->getLists()

I use :

$lists = $this->client->api('board')->lists()->all($board->getId());

Then...

new Cardlist($this->client, $list['id']);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants