-
Notifications
You must be signed in to change notification settings - Fork 21
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
Performance issue: Move GoogleAdsFailures::init to error_handler middleware #2099
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes. I've tested failures and partial failures and I get the expected response regardless of when it happens.
Just wanted to note that the before and after screenshots in the PR are identical, but I've seen the ones in #1250 (comment).
It's a shame that we can't initialize only on an error response, but it's still a great improvement to only initialize when there has actually been a request to the Google Ads API.
|
||
// Partial Failures come back with a status code of 200, so it's necessary to call GoogleAdsFailures:init every time. | ||
if ( strpos( $path, 'google-ads' ) !== false ) { | ||
GoogleAdsFailures::init(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering what happens if we ever send two requests (one after the other). However it seems that the init function only initializes a new instance if it can't find a previously initialized one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's correct.
Thanks @mikkamp for reviewing this PR.
I updated the description with the right images. Thanks again! |
Changes proposed in this Pull Request:
Closes part of #1250
The
GoogleAdsClient:init
is an expensive operation that is currently loaded whenever the Google Ads client is created. It gets triggered by the GoogleServiceProvider and is executed each time there's an admin page load or a request towp-json
.See the full details of this issue: #1250 (comment)
In this PR, we relocate
GoogleAdsFailures::init
from the GoogleAdsClient constructor to theerror_handler
middleware. This change means that GoogleAdsFailure will only be loaded when there is a request made to thegoogle-ads
API.Before this PR:
After this PR:
Shifting
GoogleAdsFailure:init
to theerror_handler
will help in cutting down the time allocated for the Google protobufs functions. However, the GL&A container is still consuming roughly 4.88% of the total loading process, therefore still some room for improvement.Screenshots:
Detailed test instructions:
General Testing
Simulate an Ads API error
google-listings-and-ads/src/API/Google/AdsCampaign.php
Line 268 in 9546add
To:
$campaign_fields['status'] = 999999
Simulate a partial failure error.
google-listings-and-ads/src/API/Google/AdsCampaign.php
Lines 557 to 560 in 9546add
With:
It shows an invalid campaign ID, because the current code is not expecting partial failures.
GoogleAdsFailures::init();
and try to change the campaign status, you will get the following error:Additional details:
Changelog entry