-
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 #2277
Refactor product issues #2277
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feature/refactor-product-stats #2277 +/- ##
==================================================================
+ Coverage 60.0% 60.3% +0.3%
+ Complexity 4184 4181 -3
==================================================================
Files 457 457
Lines 17748 17733 -15
==================================================================
+ Hits 10647 10693 +46
+ Misses 7101 7040 -61
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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 @jorgemd24 for working on this. I tested following the indications inn the description and worked for me.
I left some comments regarding the code.
I wanted to address the scenario where the job fails and some issues are inserted. I used the "created at" field, but it appears that the field will be identical for all batches. Therefore, I'll need to see alternative solutions in a follow-up PR. Any suggestions are welcome too.
Could you elaborate this? I'm not sure if I understand the issue.
* | ||
* @since x.x.x | ||
*/ | ||
protected function delete_stale_issues( string $compare = '<' ) { |
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.
💅 Maybe we might add : void
to be consistent with the rest of the class signatures.
src/DB/Table/MerchantIssueTable.php
Outdated
@@ -55,9 +55,10 @@ public static function get_raw_name(): string { | |||
* Delete stale issue records. | |||
* | |||
* @param DateTime $created_before Delete all records created before this. | |||
* @param string $compare Comparison operator to use. Default is '<'. |
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.
💅 Maybe we can delete the extra tabulation between $compare and the description.
* | ||
* @param string[] $google_ids | ||
* @param [] $statuses The list of Product View statuses. |
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.
Shouldn't be array[]
instead of []
?
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.
Additionally. PHPDoc comment doesn't contain all the necessary @throws tags derivated from $this->container->get
* | ||
* @param GoogleProductStatus[] $validated_mc_statuses Product statuses of validated products. | ||
* @param [] $product_issues Array of product issues. |
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.
💅 This might be array
instead of []
also some throw tags missing.
Thanks @puntope for the review! I addressed all your comments and replied to some of your suggestions. Regards:
I was thinking a scenario where the job fails during inserting the issues. For instance, if the job inserts some issues but others fail, such as a query taking too long, the job itself fails, and Action Scheduler will retry it. This means it would reinsert the issues that were successfully added in the initial try. The Could you please take another look at it? Thanks! |
Yes, I guess that might work. Other alternative option may be a duplicate cleanup after the AS Job batch finishes. |
src/DB/Table/MerchantIssueTable.php
Outdated
* @param array $products_ids Array of product IDs to delete issues for. | ||
* @param string $source The source of the issues. Default is 'mc'. | ||
*/ | ||
public function delete_specific_product_issues( array $products_ids, string $source = 'mc' ) { |
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.
💅 We can add :void
as a return type in the signature to be consistent with the other functions. delete_stale
also missed it, but was not introduced in this PR tho
* | ||
* @since x.x.x | ||
*/ | ||
protected function delete_stale_issues() { |
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.
💅 Missed :void
* | ||
* @since x.x.x | ||
*/ | ||
public function clear_product_statuses_cache_and_issues(): void { |
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.
💅 Maybe we can add also some tests for this new logic.
do_action( | ||
'woocommerce_gla_debug_message', | ||
sprintf( 'Merchant Center product %s not found in this WooCommerce store.', $mc_product_id ), | ||
__METHOD__ . ' in remove_invalid_statuses()', | ||
); | ||
continue; | ||
} | ||
// Unsynced issues shouldn't be shown. | ||
if ( ChannelVisibility::DONT_SYNC_AND_SHOW === $wc_product->get_meta( $visibility_meta_key ) ) { |
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.
💅 Seems that we are not covering this case in tests.
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 @jorgemd24 for all the changes.
I approve this as there are no blockers anymore and it works as defined in the PR description.
I left tho some comments regarding code and test coverage.
Changes proposed in this Pull Request:
Part of #2146 & #2250
This PR fetches the product issues using the same background job used to fetch the product statuses. This allows us to reuse the WC products that were fetched while updating the product statuses.
The logic remains mostly unchanged from before. The main difference is that previously, Google IDs were stored in the database and used to fetch the issues. With the new sync mechanism, since we don't have the Google IDs until we fetch all product statuses, we now use the data from the product statuses to obtain the Google IDs and fetch the issues.
Screenshots:
Detailed test instructions:
GET wp-json/wc/gla/mc/product-statistics/refresh
gla/jobs/update_merchant_product_statuses/process_item
see how the jobs get completed successfully.wp_gla_merchant_issues
gets populated.GET wp-json/wc/gla/mc/product-statistics
and see that you get the right stats.Additional details:
Changelog entry