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

API PULL - Overview Stats - delete stale mc statuses #2329

Merged

Conversation

jorgemd24
Copy link
Contributor

@jorgemd24 jorgemd24 commented Mar 21, 2024

Changes proposed in this Pull Request:

Part of #2146 & #2250

Since the product's MC status depends on the status in Google Merchant Center, if the product no longer exists in the MC, the local MC status will never be deleted. Hence, this PR will clear all the MC statuses, allowing us to start fresh when pulling the product MC statuses.

In the previous #2257, we refactor some code to use WC Crud classes instead of directly querying the database. However, in this scenario, I think deleting all the product's post meta _wc_gla_mc_status with a single query would be much more efficient than using the CRUD classes and loading all the products.

I increased the transient expiration time to 12 hours. Because currently, whenever a product is created, updated, or deleted, the transient cache is cleared because it calls the hooks (woocommerce_gla_batch_updated_products and woocommerce_gla_batch_deleted_products). Therefore, I believe it's unnecessary to remove the transient cache every hour if no changes to products have occurred.

add_action(
'woocommerce_gla_batch_updated_products',
function () {
$this->clear_stats_cache();
}
);
add_action(
'woocommerce_gla_batch_deleted_products',
function () {
$this->clear_stats_cache();
}
);

With the new approach of notifications, we could do something similar, once a product has been notified to Google we could clear the cache.

Screenshots:

Detailed test instructions:

  1. Call wc/gla/mc/product-statistics/refresh
  2. Go to WC -> Status -> Action Scheduler and see that the gla/jobs/update_merchant_product_statuses/process_item is scheduled.
  3. Go to page=wc-admin&path=%2Fgoogle%2Fproduct-feed and wait until the stats are fetched.
  4. If you want to check whether the postmeta has been deleted and then reinserted, you can check if the postmeta IDs in the database have changed.

Additional details:

Changelog entry

@github-actions github-actions bot added changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement. labels Mar 21, 2024
@jorgemd24 jorgemd24 changed the base branch from develop to add/display-error-job-mc-status March 21, 2024 18:28
Copy link

codecov bot commented Mar 21, 2024

Codecov Report

Attention: Patch coverage is 44.44444% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 64.3%. Comparing base (065ff6d) to head (8ec00b8).
Report is 3 commits behind head on add/display-error-job-mc-status.

Additional details and impacted files

Impacted file tree graph

@@                         Coverage Diff                         @@
##             add/display-error-job-mc-status   #2329     +/-   ##
===================================================================
+ Coverage                               62.7%   64.3%   +1.6%     
- Complexity                              4249    4251      +2     
===================================================================
  Files                                    751     458    -293     
  Lines                                  21777   18046   -3731     
  Branches                                 542       0    -542     
===================================================================
- Hits                                   13653   11606   -2047     
+ Misses                                  7668    6440   -1228     
+ Partials                                 456       0    -456     
Flag Coverage Δ
js-unit-tests ?
php-unit-tests 64.3% <44.4%> (+0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/MerchantCenter/MerchantStatuses.php 76.3% <100.0%> (+2.8%) ⬆️
src/DB/ProductMetaQueryHelper.php 0.0% <0.0%> (ø)

... and 294 files with indirect coverage changes

@jorgemd24 jorgemd24 self-assigned this Mar 21, 2024
@jorgemd24 jorgemd24 marked this pull request as ready for review March 21, 2024 18:50
@jorgemd24 jorgemd24 requested a review from a team March 21, 2024 19:11
@puntope
Copy link
Contributor

puntope commented Mar 22, 2024

With the new approach of notifications, we could do something similar, once a product has been notified to Google we could clear the cache.

I added this to the list of TODO in #2146

Copy link
Contributor

@puntope puntope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jorgemd24 thanks for working on this.

✅ LGTM the issues are refreshed and loaded as always.

I left a minor comment about the sincetag. But approved in advance

*
* @throws InvalidMeta If the meta key isn't valid.
*/
public function delete_all_values( string $meta_key ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@since tag is missed

@jorgemd24 jorgemd24 merged commit cbdcba1 into add/display-error-job-mc-status Mar 25, 2024
11 checks passed
@jorgemd24 jorgemd24 deleted the add/delete-stale-mc-statuses branch March 25, 2024 14:44
@eason9487 eason9487 mentioned this pull request Mar 26, 2024
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: add A new feature, function, or functionality was added. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants