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

Limit index length to 191 characters by default, additionally connect HPOS to verify DB tooling. #39250

Merged
merged 3 commits into from Jul 31, 2023

Conversation

vedanshujain
Copy link
Contributor

@vedanshujain vedanshujain commented Jul 14, 2023

Additionally, connect verify db tooling to order tables when they are enabled.

Submission Review Guidelines:

Changes proposed in this Pull Request:

This PR introduces two changes:

  1. It limited the index length to 191 characters as we do for other WooCommerce schema. This is needed because at least in the MyISAM engine, the maximum index size can only be 1000 bytes, which is occupied by 192 chars with utf8_mb4 encoding.
  2. It links the already existing verify_db_tool with the HPOS schema if it's enabled (or if data sync is on). This tools alerts the site admin if a table is missing.

Closes #39051

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Start with a site with posts authoritative and sync disabled. Delete the HPOS tables if they already exist by going to WooCommerce > Status > Tools and running the Delete the custom orders tables tool.
  2. Add this filter to simulate the error first:
add_filter( 'woocommerce_database_max_index_length', function () {
	return 320; // will cause error on MyISAM but works fine on InnoDB.
} );
  1. We will now modify the code to create one of the tables with MyISAM which will simulate the error. Edit this file: https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php#L2664 so that it now says ) $collate ENGINE = MyISAM; instead of just ) $collate ;.
  2. Once the file is edited, let's try to create the table. Go to WooCommerce > Settings > Advance > Features and enable the option to keep posts and orders in sync. This will create all tables but the meta table, which will fail with error: Specified key was too long; max key length is 1000 bytes.
  3. Go to WooCommerce > Status > Tools and run the Verify base database tables tool. It will identify the missing table and show this error: Verifying database... One or more tables are still missing: wp_wc_orders_meta.
  4. Now, remove the filter that we added in Step 2. Go to WooCommerce > Settings > Advance > Features again and enable/disable the sync feature. This will trigger the table creation routine again.
  5. Come back to WooCommerce > Status > Tools and run the Verify base database tables tool. It should show that all tables are present as expected.

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement

Message

Comment

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Jul 14, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jul 14, 2023

Test Results Summary

Commit SHA: 6d11563

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202610m 53s
E2E Tests1890019020814m 33s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@vedanshujain vedanshujain marked this pull request as ready for review July 14, 2023 12:58
@vedanshujain vedanshujain requested review from a team and rrennick and removed request for a team July 14, 2023 12:58
@github-actions
Copy link
Contributor

Hi @rrennick,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

1 similar comment
@github-actions
Copy link
Contributor

Hi @rrennick,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

Additionally, connect verify db tooling to order tables when they are enabled.
@rrennick
Copy link
Contributor

This will create all tables but the meta table, which will fail with error: Specified key was too long; max key length is 1000 bytes.

@vedanshujain Should we update this message to reflect the limit imposed by the filter?

Copy link
Contributor

@rrennick rrennick left a comment

Choose a reason for hiding this comment

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

Code looks good but I didn't test it yet. I left that for after resolving the discussion points.

@@ -366,6 +366,7 @@ private function handle_data_sync_option_changed( string $feature_id ) {

if ( ! $this->data_synchronizer->check_orders_table_exists() ) {
$this->data_synchronizer->create_database_tables();

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks accidental.

@@ -2584,6 +2584,23 @@ public function get_database_schema() {
$operational_data_table_name = $this->get_operational_data_table_name();
$meta_table = $this->get_meta_table_name();

/**
Copy link
Contributor

@rrennick rrennick Jul 14, 2023

Choose a reason for hiding this comment

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

Would it be worth adding this filter in its own function in a utility/helper class as we may find more uses for it as we work through some of the other upcoming data storage projects?

@rrennick
Copy link
Contributor

@vedanshujain Not for this PR but there are couple small things I noticed:

  • When the meta table was missing the delete tables tool wasn't listed in the tools even though the other tables were
  • The sync went ahead whether or not the meta table was present. It would be better if it was stopped and the merchant had a notification of some kind

Copy link
Contributor

@rrennick rrennick left a comment

Choose a reason for hiding this comment

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

Nice work on this @vedanshujain . It tested great for me.

@rrennick rrennick added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Jul 31, 2023
@nigeljamesstevenson nigeljamesstevenson added needs: internal testing Indicates if the PR requires further testing conducted by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Jul 31, 2023
@nigeljamesstevenson
Copy link
Contributor

Thanks a lot for the input on this @rrennick - much appreciated! @vedanshujain, do you want us to create Issues for the suggestions that Ron has made?

@nigeljamesstevenson nigeljamesstevenson merged commit fa2aba5 into trunk Jul 31, 2023
22 of 23 checks passed
@nigeljamesstevenson nigeljamesstevenson deleted the fix/39051 branch July 31, 2023 20:48
@github-actions github-actions bot added this to the 8.1.0 milestone Jul 31, 2023
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Jul 31, 2023
@coreymckrill
Copy link
Collaborator

@vedanshujain I just noticed that WC is giving a warning that WC Smooth Generator is not compatible with HPOS, even though it has been declaring compatibility for quite a while now. I used git bisect to trace the change to this PR. From the changeset I don't immediately see what could be causing this, but wanted to give a heads up, as this could be affecting other extensions as well.

@tammullen tammullen removed the needs: analysis Indicates if the PR requires a PR testing scrub session. label Aug 1, 2023
@rrennick
Copy link
Contributor

rrennick commented Aug 1, 2023

I used git bisect to trace the change to this PR. From the changeset I don't immediately see what could be causing this

It's not registered as compatible with the two new features added in this PR.

coreymckrill added a commit that referenced this pull request Aug 1, 2023
In #38993, the `custom_order_tables` feature was split into two
separate features, one for choosing which tables to use, and one for
toggling data synchronization. My understanding is that this was done
in order to have both of those settings appear on the Features settings
page, instead of having to create a separate page for other
HPOS-specific settings. However, this added some extra complexity,
which then led to #39250 causing a regression where extensions that
declared compatibility with HPOS were no longer recognized as
compatible.

With this PR, we're reverting back to only having one "feature" for
HPOS, but introducing a way to add additional setting controls to the
Features settings page.
coreymckrill added a commit that referenced this pull request Aug 2, 2023
This is a piece of a change that is already in trunk, but it needs to
be backported to 8.0 (see #39250). This ensures that the feature ID and
the option key match for each of the two HPOS-related features that
were introduced in #38993.
jonathansadowski pushed a commit that referenced this pull request Aug 2, 2023
* Ensure FeaturesController is aware of correct HPOS option keys

This is a piece of a change that is already in trunk, but it needs to
be backported to 8.0 (see #39250). This ensures that the feature ID and
the option key match for each of the two HPOS-related features that
were introduced in #38993.

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <github-actions@github.com>
coreymckrill added a commit that referenced this pull request Aug 3, 2023
In #38993, the `custom_order_tables` feature was split into two
separate features, one for choosing which tables to use, and one for
toggling data synchronization. My understanding is that this was done
in order to have both of those settings appear on the Features settings
page, instead of having to create a separate page for other
HPOS-specific settings. However, this added some extra complexity,
which then led to #39250 causing a regression where extensions that
declared compatibility with HPOS were no longer recognized as
compatible.

With this PR, we're reverting back to only having one "feature" for
HPOS, but introducing a way to add additional setting controls to the
Features settings page.
coreymckrill added a commit that referenced this pull request Aug 5, 2023
In #38993, the `custom_order_tables` feature was split into two
separate features, one for choosing which tables to use, and one for
toggling data synchronization. My understanding is that this was done
in order to have both of those settings appear on the Features settings
page, instead of having to create a separate page for other
HPOS-specific settings. However, this added some extra complexity,
which then led to #39250 causing a regression where extensions that
declared compatibility with HPOS were no longer recognized as
compatible.

With this PR, we're reverting back to only having one "feature" for
HPOS, but introducing a way to add additional setting controls to the
Features settings page.
coreymckrill added a commit that referenced this pull request Aug 17, 2023
In #38993, the `custom_order_tables` feature was split into two
separate features, one for choosing which tables to use, and one for
toggling data synchronization. My understanding is that this was done
in order to have both of those settings appear on the Features settings
page, instead of having to create a separate page for other
HPOS-specific settings. However, this added some extra complexity,
which then led to #39250 causing a regression where extensions that
declared compatibility with HPOS were no longer recognized as
compatible.

With this PR, we're reverting back to only having one "feature" for
HPOS, but introducing a way to add additional setting controls to the
Features settings page.
coreymckrill added a commit that referenced this pull request Aug 29, 2023
In #38993, the `custom_order_tables` feature was split into two
separate features, one for choosing which tables to use, and one for
toggling data synchronization. My understanding is that this was done
in order to have both of those settings appear on the Features settings
page, instead of having to create a separate page for other
HPOS-specific settings. However, this added some extra complexity,
which then led to #39250 causing a regression where extensions that
declared compatibility with HPOS were no longer recognized as
compatible.

With this PR, we're reverting back to only having one "feature" for
HPOS, but introducing a way to add additional setting controls to the
Features settings page.
coreymckrill added a commit that referenced this pull request Sep 1, 2023
In #38993, the `custom_order_tables` feature was split into two
separate features, one for choosing which tables to use, and one for
toggling data synchronization. My understanding is that this was done
in order to have both of those settings appear on the Features settings
page, instead of having to create a separate page for other
HPOS-specific settings. However, this added some extra complexity,
which then led to #39250 causing a regression where extensions that
declared compatibility with HPOS were no longer recognized as
compatible.

With this PR, we're reverting back to only having one "feature" for
HPOS, but introducing a way to add additional setting controls to the
Features settings page.
@Poocey Poocey mentioned this pull request Sep 13, 2023
2 tasks
coreymckrill added a commit that referenced this pull request Sep 20, 2023
In #38993, the `custom_order_tables` feature was split into two
separate features, one for choosing which tables to use, and one for
toggling data synchronization. My understanding is that this was done
in order to have both of those settings appear on the Features settings
page, instead of having to create a separate page for other
HPOS-specific settings. However, this added some extra complexity,
which then led to #39250 causing a regression where extensions that
declared compatibility with HPOS were no longer recognized as
compatible.

With this PR, we're reverting back to only having one "feature" for
HPOS, but introducing a way to add additional setting controls to the
Features settings page.
coreymckrill added a commit that referenced this pull request Sep 28, 2023
In #38993, the `custom_order_tables` feature was split into two
separate features, one for choosing which tables to use, and one for
toggling data synchronization. My understanding is that this was done
in order to have both of those settings appear on the Features settings
page, instead of having to create a separate page for other
HPOS-specific settings. However, this added some extra complexity,
which then led to #39250 causing a regression where extensions that
declared compatibility with HPOS were no longer recognized as
compatible.

With this PR, we're reverting back to only having one "feature" for
HPOS, but introducing a way to add additional setting controls to the
Features settings page.
coreymckrill added a commit that referenced this pull request Oct 3, 2023
In #38993, the `custom_order_tables` feature was split into two
separate features, one for choosing which tables to use, and one for
toggling data synchronization. My understanding is that this was done
in order to have both of those settings appear on the Features settings
page, instead of having to create a separate page for other
HPOS-specific settings. However, this added some extra complexity,
which then led to #39250 causing a regression where extensions that
declared compatibility with HPOS were no longer recognized as
compatible.

With this PR, we're reverting back to only having one "feature" for
HPOS, but introducing a way to add additional setting controls to the
Features settings page.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: internal testing Indicates if the PR requires further testing conducted by Solaris plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HPOS SQL Code Too Large
5 participants