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

Authentication requests are always executed #149

Open
Toflar opened this issue Nov 23, 2018 · 7 comments
Open

Authentication requests are always executed #149

Toflar opened this issue Nov 23, 2018 · 7 comments
Labels

Comments

@Toflar
Copy link

Toflar commented Nov 23, 2018

Hey everybody,

We're using the library to request data using Guzzle.
The issue we're having is that the Akeneo SDK is always executing authentication requests even though a request is actually already in the cache.
Here's what we're using:

$stack = HandlerStack::create();
$stack->push(new CacheMiddleware(new GreedyCacheStrategy(....)));

$httpClient = Client::createWithConfig(array_merge(['handler' => $stack], $config));

$builder = new AkeneoPimClientBuilder($baseUri);
$builder->setHttpClient($httpClient);
$api = $builder->buildAuthenticatedByPassword(...);

So in other words, because Akeneo does not send any http caching headers we do use the GreedyCacheStrategy to force greedy caching. We then set this client using the setHttpClient() method. However, the ->buildAuthenticatedByPassword() wraps this client and always executes an authentication request even though the inner client actually has a middleware that knows the response already from the cache. Thus we're executing a number of nonsense authentication requests all the time.

Is there any recommendation on how to implement caching on the SDK itself?

@FabienSalles
Copy link

Hello,

I also would like to have recommendation for this.

By my side, I decorated each API class that I wanted to cache (FamilyApi, AttributeApi...) and overrided the AkeneoPimClientBuilder class to use them.

It is a little dirty but this works form me and you can have differents caching strategies by API.

@ahocquard
Copy link
Collaborator

ahocquard commented Jan 17, 2019

Hello and sorry for the late reply,

In order to better understand it:

  • Is the client doing one authentication request per request? Not expected.
  • Is the client doing one authentication request at first HTTP call and then it's authenticated? Expected.

@Toflar
Copy link
Author

Toflar commented Jan 17, 2019

None of the questions are related to this issue, sorry.
The problem is not that multiple authentication requests are executed. The problem is the fact that it is executed at all.

The AuthenticatedHttpClient wraps the real HttpClient to execute an authentication request during the first request (https://github.com/akeneo/api-php-client/blob/master/src/Client/AuthenticatedHttpClient.php#L52).

This means that if the instance of HttpClient is configured to use caching, the wrapping AuthenticatedHttpClient doesn't know so it always executes an authentication request, even if the real HttpClient instance afterwards doesn't execute any request because it takes it from the cache.

@ahocquard
Copy link
Collaborator

Hello, I better understand your problem.

Your authentication response is returned from the cache itself, which will not work.
I think that's the correct behavior is to prevent it directly from the authentication response in the API (server side).

I will talk with my teammates and keep you in touch about this problem.

@Toflar
Copy link
Author

Toflar commented Jun 23, 2020

Any updates on this? This is still a major performance bottleneck...

@ahocquard
Copy link
Collaborator

Hello,

I understand you issue, but I'm wondering how a single authentication request leads to performance bottleneck? In which context do you use the HTTP client? CLI or HTTP request? Can't you set up a token this way: https://api.akeneo.com/php-client/authentication.html#example?

@Toflar
Copy link
Author

Toflar commented Jun 23, 2020

How does it matter how long that request takes? It's a completely useless request if I already have the data in cache.

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

4 participants