Skip to content

Use in-memory adjustments in OrderUpdater#1397

Merged
jhawthorn merged 1 commit intosolidusio:masterfrom
jhawthorn:in_memory_order_adjustments_update
Sep 1, 2016
Merged

Use in-memory adjustments in OrderUpdater#1397
jhawthorn merged 1 commit intosolidusio:masterfrom
jhawthorn:in_memory_order_adjustments_update

Conversation

@jhawthorn
Copy link
Copy Markdown
Contributor

@jhawthorn jhawthorn commented Aug 18, 2016

From @mtomov's suggestion in #1389

This currently fails because this line in ItemAdjustments causes the order's adjustments to become stale.

@jrochkind
Copy link
Copy Markdown
Contributor

jrochkind commented Aug 18, 2016

That's an confusing comment at the line @jhawthorn mentions "This is done intentionally to avoid loading the association." But it doesn't avoid loading the association at all, it does load the association... then caches it.

Since it says its' working around a bug elsewhere in spree, and when that bug is remedied it should be removed.... I wonder if that mysterious bug elsewhere in spree is covered by tests, so if the tests still pass it means that line isn't needed?

@cbrunsdon
Copy link
Copy Markdown
Contributor

I think this is a good change ( 👍 ) and would be down with killing that memoization

@jrochkind
Copy link
Copy Markdown
Contributor

jrochkind commented Aug 19, 2016

Rails caches/memoizes associations itself of course -- it's unclear why ordinary AR caching isn't sufficient here.

@jhawthorn
Copy link
Copy Markdown
Contributor Author

Running assoc.all.to_a is different than assoc.to_a in that it does not load and cache the adjustments association.

> item = Spree::LineItem.last
> item.adjustments.loaded?
=> false
> item.adjustments.all.to_a
Spree::Adjustment Load (0.6ms)  SELECT "spree_adjustments".* FROM ...
[#<Spree::Adjustment:...
> item.adjustments.loaded?
=> false
> item.adjustments.all.to_a
Spree::Adjustment Load (0.6ms)  SELECT "spree_adjustments".* FROM ...
[#<Spree::Adjustment:...
> item.adjustments.to_a
Spree::Adjustment Load (0.6ms)  SELECT "spree_adjustments".* FROM ...
[#<Spree::Adjustment:...
> item.adjustments.loaded?
=> true
> item.adjustments.to_a # (cached. no query)
[#<Spree::Adjustment:...

There's a few dozen spec failures when using the association directly.

The reason this is done is that there are a number of things that operate on adjustments without going through the association.. A simple example is this line in create_item_adjustments.rb.

We'll have to ensure everything that operates on adjustments does so through the items association and keeps it fresh.

@jrochkind
Copy link
Copy Markdown
Contributor

Ah, I see, I missed that all and it's meaning. Hmm.

Would it be at all useful for some places that want to operate directly without using the association to call adjustments.reset after doing so, so next time the association is loaded it will be fresh?

But that still requires individual discovery and attention to every place that does this, and might not be a good idea anyway.

@jhawthorn jhawthorn force-pushed the in_memory_order_adjustments_update branch 2 times, most recently from 282da6b to d163b5b Compare August 31, 2016 18:20
@cbrunsdon
Copy link
Copy Markdown
Contributor

Looks good to me 👍

@mtomov
Copy link
Copy Markdown
Contributor

mtomov commented Aug 31, 2016

To me as well. On the second line change you might as well add a question mark after eligible - select(&:eligible?) - to make it consistent

@jhawthorn jhawthorn force-pushed the in_memory_order_adjustments_update branch from d163b5b to 555267e Compare September 1, 2016 18:36
@jhawthorn
Copy link
Copy Markdown
Contributor Author

To me as well. On the second line change you might as well add a question mark after eligible - select(&:eligible?) - to make it consistent

Good catch. I made this change.

@jhawthorn jhawthorn merged commit 1f86937 into solidusio:master Sep 1, 2016
@jhawthorn jhawthorn deleted the in_memory_order_adjustments_update branch September 1, 2016 18:53
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.

4 participants