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

improve performance of related entities retrieval #62

Open
jmfeurprier opened this issue Aug 4, 2017 · 1 comment
Open

improve performance of related entities retrieval #62

jmfeurprier opened this issue Aug 4, 2017 · 1 comment
Labels

Comments

@jmfeurprier
Copy link
Contributor

jmfeurprier commented Aug 4, 2017

Hi,

we encounter performance issues with related entities.

Given we make this API call:

GET https://api/articles/12345678-4792-11e7-88db-f23c9124c2b0

Which returns :

{
    "@context": "\/contexts\/Article",
    "@id": "\/articles\/12345678-4792-11e7-88db-f23c9124c2b0",
    "@type": "Article",
    "id": "12345678-4792-11e7-88db-f23c9124c2b0",
    "title": "foo bar",
    "tags": [
        "\/tags\/331a2c47-164a-11e7-8a8a-f23c9124c2b0",
        "\/tags\/331a658c-164a-11e7-8a8a-f23c9124c2b0",
        "\/tags\/331a71cc-164a-11e7-8a8a-f23c9124c2b0",
        "\/tags\/9c828580-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9c82e2b1-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9c834c02-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9c850c8b-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9c86ca17-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9cc9f244-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9cd4d60e-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9d186137-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9d194643-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9d1f1245-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9d1fe224-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9d33f4f4-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9d37d44d-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9d4353fe-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9d5d71fd-75f3-11e7-8820-f23c9124c2b0",
        "\/tags\/9da0e8d6-75f3-11e7-8820-f23c9124c2b0"
    ]
}

When we iterate over the entity tags collection ($article->getTags()), each iteration makes an API call to retrieve the tag entity:

GET https://api/tags/331a2c47-164a-11e7-8a8a-f23c9124c2b0
GET https://api/tags/331a658c-164a-11e7-8a8a-f23c9124c2b0
GET https://api/tags/331a71cc-164a-11e7-8a8a-f23c9124c2b0
GET https://api/tags/9c828580-164a-11e7-8a8a-f23c9124c2b0
...

Which kills the performances of our application.

Embedding the tags in the article API response is not an option in our case (for a lot of reasons).

So my question is: is there a way to tell the API client to retrieve all the tags at once instead of retrieving them one by one ?

@jdeniau
Copy link
Member

jdeniau commented Aug 4, 2017

The fact is that the implementation of how you fetch all you calls is really depending on our architecture.

You may have a route like this: /tags/t1,t2,t3 which will make a "get" on tags t1, t2 and t3.
But you can also have a route like this: /tags?article=a1 with will list all tag with the tag serialization for article a1.
You may also have a route like this /articles/a1/tags !

At Mapado, we choose the second option (/tags?article=...), but in those case we can not use the automatic getter, we need to explicitly make 2 calls, one on /article/a1 and one for the tags /tags?article=a1

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

No branches or pull requests

2 participants