-
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
Refactor Product issues and fix issues when getting stats for a fresh MC account #2306
Refactor Product issues and fix issues when getting stats for a fresh MC account #2306
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feature/refactor-product-stats #2306 +/- ##
==================================================================
+ Coverage 60.5% 64.3% +3.7%
- Complexity 4183 4245 +62
==================================================================
Files 457 458 +1
Lines 17745 18024 +279
==================================================================
+ Hits 10742 11584 +842
+ Misses 7003 6440 -563
Flags with carried forward coverage won't be shown. Click here to find out more.
|
…e-and-product-status-code
|
||
// Clear the cache if we are not in the middle of updating/deleting all products. Otherwise, we might update the product stats for each individual batch. | ||
// See: ClearProductStatsCache::register | ||
if ( $update_all_products_job->can_schedule( null ) && $delete_all_products_job->can_schedule( null ) ) { |
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.
Why can_schedule
and not is_running
?
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.
Because is_running
is a protected method, I understand that maybe it would be a bit easier to read the code if we use a method name similar to is_running
. Although I think the comment that I left explains what we are doing.
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.
More than the naming I was more thinking about the logic in can_schedule. That also checks some conditions. If MC connected for example. But if that doesn't create a problem I think we are good with can_schedule
Hi @jorgemd24 seems like is looking good. However, I cannot see the products populated (I waited a while) 🤔 I will check tomorrow morning to verify if they loaded already. |
Thanks @puntope for the review!
Do you mean that the products aren't synchronized in the MC? If that's the case, it's worth mentioning that we haven't changed any logic with the product syncer. We've only refactored how we retrieve the product stats. |
Ok, thanks @jorgemd24 Let's suppose that is another issue unrelated to this PR. However, I synced a product manually via Connection test page, just to check: When I run it on this branch I got {
"timestamp": 1710522408,
"statistics": {},
"scheduled_sync": 23,
"loading": true,
"error": null
} if I checkout develop and run it again I got {
"timestamp": 1710522512,
"statistics": {
"active": 0,
"expiring": 0,
"pending": 0,
"disapproved": 1,
"not_synced": 0
},
"scheduled_sync": 23
} In the dashboard. In develop I see the product as "disapproved", in this branch the product keeps as "Not synced" and the statistics shows N/A Just wonder if this is expected. And if not, I wonder if that's related to this PR or is a separated issue. |
Hi @puntope, Thanks for your comments, regards:
On that response, it appears that the job Regarding the screenshots, that' expected. I'm currently working on adding some spinning icons to indicate when the |
Hi @jorgemd24 All the jobs mentioned are completed. But I still get the same response:
However, I was able to see the stats finally in the dashboard. Let me know if that refresh stats response is expected or we should continue investigating. |
Hi @puntope,
That response indicates that the
I guess later on
If that's the case, it's expected. Keep in mind, that the UI isn't refreshing the data at the moment (at least that you refresh the page manually) because in this PR only contains the backend. |
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.
Hi @jorgemd24 Finally the issue was because I thought calling wc/gla/mc/product-statistics/refresh
would return the stats
Calling wc/gla/mc/product-statistics
return the right response
{
"timestamp": 1710842811,
"statistics": {
"active": 0,
"expiring": 0,
"pending": 0,
"disapproved": 1,
"not_synced": 18
},
"scheduled_sync": 23,
"loading": false,
"error": null
}
Changes proposed in this Pull Request:
Part of #2146 & #2250
While I was testing the new approach with a fresh Merchant Center account I found some issues that this PR fixes:
mc/settings/sync
, which kicks off thewoocommerce_gla_mc_settings_sync hook
and schedules theUpdateAllProducts
job. As each batch gets processed, it triggers thewoocommerce_gla_batch_updated_products
hook, clearing the merchant statuses cache for each batch. This can create a loop: stats are fetched, and then deleted when the batch is processed. So, if the user refreshes the stats, it'll redo the calculation only to delete them again.google-listings-and-ads/src/Event/ClearProductStatsCache.php
Lines 38 to 51 in f4aaafb
This PR checks if
UpdateAllProducts
orDeleteAllProducts
jobs is running before clearing the cache and will refresh the data when the batches are completed.MerchantProductViewReportQuery
andget_productstatuses_batch
are returned asnull
if there is no data, instead of an empty array, this PR fixes this using?? []
.Also, this PR tweaks some parts of the code:
get_synced_google_ids
as it is not used anymore.handle_complete_mc_statuses_fetching
gets called, we check if the intermediate data is set. If it is, we mark the process as complete. However, I reckon it's safer to return a default intermediate state just in case the data somehow gets deleted. This way, the process can always be completed.$this->clear_cache();
fromclear_product_statuses_cache_and_issues
because when the product stats are updated, the transient gets updated automatically. This way, the user won't even notice the process happening.Screenshots:
Detailed test instructions:
update_all_products
jobs finish, it triggersupdate_merchant_product_statuses
.update_merchant_product_statuses
is done, verify that the product statistics are displayed and that the account, pre-sync, and production issues are populated. (Dashboard -> Produc Feed -> Overview)GET wc/gla/mc/product-statistics/refresh
and check if the stats and product issues are updated accordingly.Additional details:
Changelog entry