-
-
Notifications
You must be signed in to change notification settings - Fork 725
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
Remove old abandoned carts #6740
Merged
Matt-Yorkley
merged 8 commits into
openfoodfoundation:master
from
Matt-Yorkley:carts-cleanup
Jan 29, 2021
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4230d46
Remove carts older than 6 months
Matt-Yorkley 0a88712
Clear orphaned records in join table spree_option_value_line_items
Matt-Yorkley 3fddaba
Extract private methods
Matt-Yorkley e6c59fb
Update data retention periods
Matt-Yorkley 85c489d
Ignore carts with failed payments in cleanup
Matt-Yorkley d502320
Enable cascading deletes
Matt-Yorkley 4f7c806
Create class to map join table and simplify code
Matt-Yorkley 9791287
Run data cleanup job at 4:30am
Matt-Yorkley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module Spree | ||
class OptionValuesLineItem < ActiveRecord::Base | ||
belongs_to :line_item, class_name: 'Spree::LineItem' | ||
belongs_to :option_value, class_name: 'Spree::OptionValue' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class AddCascadingDeletes < ActiveRecord::Migration | ||
def change | ||
# Updates foreign key definitions between orders, shipments, and inventory_units | ||
# to allow for cascading deletes at database level. If an order is intentionally | ||
# deleted *without callbacks*, it's shipments and inventory units will be removed | ||
# cleanly without throwing foreign key errors. | ||
|
||
remove_foreign_key :spree_shipments, name: "spree_shipments_order_id_fk" | ||
add_foreign_key :spree_shipments, :spree_orders, column: 'order_id', | ||
name: 'spree_shipments_order_id_fk', on_delete: :cascade | ||
|
||
remove_foreign_key :spree_inventory_units, name: 'spree_inventory_units_shipment_id_fk' | ||
add_foreign_key :spree_inventory_units, :spree_shipments, column: 'shipment_id', | ||
name: 'spree_inventory_units_shipment_id_fk', on_delete: :cascade | ||
|
||
remove_foreign_key :spree_inventory_units, name: 'spree_inventory_units_order_id_fk' | ||
add_foreign_key :spree_inventory_units, :spree_orders, column: 'order_id', | ||
name: 'spree_inventory_units_order_id_fk', on_delete: :cascade | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I thought of spree_option_values_line_items as a table to clear as well.
Looking at the DB I think we still have tables related to spree promotions... we could delete those. A different clear up...
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.
I just had a quick look at this, but I'm a bit nervous about proceeding in deleting those records as part of this task. In most cases
option_values
seem to be related to variants and products (with clear join tables / classes / associations representing the joins), but I can't see anywhere that explicitly defines or delineatesoption_values
records' connection to line items as being separate from variants. It seems pretty murky. Am I missing something?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.
I think you are missing this:
line_item.rb
has_and_belongs_to_many :option_values, join_table: 'spree_option_values_line_items',
class_name: 'Spree::OptionValue'
and extensively used in concern VariantAndLineItemNaming.
I dont think option_values are directly associated with products but are associated with variants in
spree_option_values_variants is for variants.
I think it's safe to delete stuff from spree_option_values_line_items for the old_line_items you delete here.
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.
Okay, I've added this in, but it required some raw SQL, as we're using
#delete_all
on the other queries to avoid instantiating the objects or triggering callbacks and we don't have a "nice" way of calling AR methods directly on the contents of that join table.Also worth noting: we already have some orphaned records in this join table (
spree_option_values_line_items
) in production, so those will be cleared up as well 👍