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

Update biling and shipping address indexes. #35121

Merged
merged 5 commits into from
Oct 19, 2022
Merged

Update biling and shipping address indexes. #35121

merged 5 commits into from
Oct 19, 2022

Conversation

vedanshujain
Copy link
Contributor

@vedanshujain vedanshujain commented Oct 17, 2022

All Submissions:

Changes proposed in this Pull Request:

Looks like we were not saving _billing_address_index and _shipping_address_index metadata on update (we were doing it on create, though). This PR addresses the issue by updating the index metadata on updates as well.

Closes #34989 .

How to test the changes in this Pull Request:

  1. With COT enabled and sync off, create an order with no address field set. Update the status to anything other than draft.
  2. Update the address now to some value, and search for it in the admin list screen. Without this PR you won't see the order listed. Checkout this PR and update the order again with another address, you will now be able to search for it.

Note that after #35150 , these meta fields won't be needed anymore.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> run changelog add?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Oct 17, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 17, 2022

Test Results Summary

Commit SHA: 99436b3

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests18800201900m 57s
E2E Tests186003018918m 13s

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 requested review from a team and barryhughes and removed request for a team October 18, 2022 10:15
Copy link
Member

@barryhughes barryhughes left a comment

Choose a reason for hiding this comment

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

Looks good 👍


I did notice a problem while testing—however it is not the result of your change, it was an oversight in the original PR that added this system to HPOS, so let me know if you prefer we follow-up via a separate issue/PR.

What I observed was that instead of updating the _<TYPE>_address_index fields (or creating that entry if it does not already exist), what we actually seem to be doing is add a new meta record each time.

You can see this if you repeat point 2 in your testing instructions a few times. In the database, we end up with something like:

id order_id meta_key meta_value
12345 100 _billing_address_index 123 My Street, London
12346 100 _billing_address_index 123 My Street, Birmingham
12347 100 _billing_address_index 345 Some Avenue, Glasgow

Apart from the fact this is adding unnecessary rows, it arguably reduces the accuracy of search (using the above example, I can still surface order 100 by searching for London, even though that has since been corrected to Glasgow).

The problem, I believe, is that calls to WC_Data::update_meta_data() always add unless the existing meta ID is also specified, which we aren't currently doing.


Hope the above makes sense. We can go ahead and merge (and one of us can fix the above separately), or we can address here if that's expedient.

@vedanshujain
Copy link
Contributor Author

I see, I am going to merge this, and open another issue to track preventing duplicates on updates.

@vedanshujain vedanshujain merged commit 5b6ddf0 into trunk Oct 19, 2022
@vedanshujain vedanshujain deleted the fix/34989 branch October 19, 2022 10:51
@github-actions github-actions bot added this to the 7.2.0 milestone Oct 19, 2022
@github-actions
Copy link
Contributor

Hi @vedanshujain, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:

  • Add the release: add testing instructions label

@vedanshujain
Copy link
Contributor Author

I see, I am going to merge this, and open another issue to track preventing duplicates on updates.

Follow up PR (WIP) #35192

@jonathansadowski jonathansadowski modified the milestones: 7.2.0, 7.1.0 Oct 20, 2022
github-actions bot pushed a commit that referenced this pull request Oct 20, 2022
* Update biling and shipping address indexes.

* Add changelog.

* Code standard fixes.

* Add unit test for search after update.

* PHPCS fixes.
jonathansadowski pushed a commit that referenced this pull request Oct 20, 2022
* Update biling and shipping address indexes. (#35121)

* Update biling and shipping address indexes.

* Add changelog.

* Code standard fixes.

* Add unit test for search after update.

* PHPCS fixes.

* Prep for cherry pick 35121

Co-authored-by: Vedanshu Jain <vedanshu.jain.2012@gmail.com>
Co-authored-by: WooCommerce Bot <no-reply@woocommerce.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[COT/HPOS] Order search results missing "Search results for: " subtitle
3 participants