fix: Don't refresh all cart leafs on every article write - #188
Draft
sveneberth wants to merge 2 commits into
Draft
fix: Don't refresh all cart leafs on every article write#188sveneberth wants to merge 2 commits into
sveneberth wants to merge 2 commits into
Conversation
`CartItemSkel.article` used the default `updateLevel` (`RelationalUpdateLevel.Always`): every write of an article spawned an `update_relations` task that refreshes *every* cart leaf referencing it -- including years-old abandoned baskets. With frequent article imports this floods the task queue and, combined with broken tree data, produced endlessly retried tasks. The refresh has no user-visible effect: the `shop_*` refKeys are a snapshot taken when the article is put into the cart, and current prices are always computed live via the `price` bone. Use `RelationalUpdateLevel.OnValueAssignment` instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
CartItemSkel.articleuses the defaultupdateLevelofRelationalBone, which isRelationalUpdateLevel.Always. Consequence: every write of an article spawns anupdate_relationstask that refreshes everycart_leafreferencing that article — including years-old abandoned session baskets.In a production system with frequent article imports this:
cart_removeto prevent orphans #184), producedupdate-relationstasks that failed with 408 and were retried forever.Why the refresh is not needed
shop_*refKeys of the relation are a snapshot taken when the article is put into the cart (copy_article_values) — the skeleton itself documents them as "Bones to store a frozen copy of the article values".pricebone (ComputeMethod.Always→Price→article_skel_full, which reads the full article entity, not the refKeys).is_frozenin cart computes and mutation paths #185).So the automatic relation refresh performs work that has no effect on what customers see or pay.
Solution
Set
updateLevel=RelationalUpdateLevel.OnValueAssignmentonCartItemSkel.article; the refKeys snapshot is then only written when the relation itself is (re)assigned. Docstring on the bone explains the reasoning.Impact to discuss
Projects that read the
article.dest.shop_*refKeys of open carts directly (instead of the leaf's ownshop_*copies or thepricebone) would no longer see article changes reflected automatically. If that is a supported use case, an alternative would be a targeted refresh of only active carts — but the default of refreshing every historic leaf on every article write seems clearly unintended.🤖 Generated with Claude Code