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

Clone user addresses instead of sharing #11712

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fkoessler
Copy link
Contributor

Order#bill_address and Order#ship_address use the
dependent: :destroy option. We should not share
user addresses with orders or the user addresses might
be deleted. OrderMerger destroys orders for example.

Order#bill_address and Order#ship_address use the
dependent: :destroy option. We should not share
user addresses with orders or the user addresses might
be deleted. OrderMerger destroys orders for example.
@viezly
Copy link

viezly bot commented May 31, 2022

Changes preview:

Legend:

👀 Review pull request on Viezly

@damianlegawiec
Copy link
Member

@fkoessler this was the case before the address book was merged into spree core.

The end result was that in bigger stores the addresses table could grow to up 50+ million records. It was unmanageable.

Currently, you cannot delete an address that belongs to completed orders.

@fkoessler
Copy link
Contributor Author

Hello @damianlegawiec , thank you for your feedback.
I understand the problem with duplicating all addresses.

I noticed the issue because one of my user had bill_address_id / ship_address_id that link to deleted addresses after OrderMerger deleted an incomplete Order: https://github.com/spree/spree/blob/main/core/app/models/spree/order_merger.rb#L23
This is an problem too.

Also, I noticed that addresses were cloned in other places in the Spree code base:

It's a bit confusing, I could not find out if Spree expects addresses to be shared or cloned.
I think a single strategy should be used throughout the codebase.

What do you think?

@fkoessler
Copy link
Contributor Author

Related to: #11682

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants