Conversation
Contributor
les-adhoc
force-pushed
the
18.0-h-123231-les
branch
from
August 4, 2026 21:25
b7232e6 to
e2b457f
Compare
… cron run A full pass over the catalog used to depend on N chained runs: each run processed 1000 products and enqueued the next one with a cron trigger. That chain is fragile. If a batch fails (data error, contention, cron time limit) the remaining batches are not executed until the next scheduled run, monthly by default, and the catalog stays half updated. There is also no observable point where the pass is complete: a successful run only means that batch went through, not that the catalog was covered. A run now walks every pending batch. The commit per batch is kept, so the transaction is no longer than before, and if MAX_BATCHES_PER_CRON_RUN is exhausted the continuation is still enqueued with the trigger. The cursor is carried in memory across batches instead of being re-read from the parameter on every batch. It is persisted with a direct UPDATE because set_param would clear the registry cache, which left the ORM cache of the record stale and made the loop reprocess the same batch over and over. The record is invalidated after the UPDATE so any later reader gets the fresh value, and the batch search uses a limit instead of loading the whole table to count it. Also resolves _bom_find once per record in product_replenishment_cost_mrp, which was called up to three times through a ternary that repeated the whole expression, and adds the first tests of that module.
les-adhoc
force-pushed
the
18.0-h-123231-les
branch
from
August 12, 2026 15:51
e2b457f to
1ac69e4
Compare
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
A full pass over the catalog used to depend on N chained runs:
_cron_update_cost_from_replenishment_cost()processed 1000 products per run, stored a cursor inir.config_parameterand enqueued the next batch withcron._trigger().That chain is fragile:
What changes
MAX_BATCHES_PER_CRON_RUN(50) is exhausted the continuation is still enqueued with the trigger.UPDATEbecauseset_paramwould clear the registry cache — which left the ORM cache of the record stale and made the loop reprocess the same batch over and over. The record is invalidated after theUPDATEso any later reader gets the fresh value.limit=batch_size + 1instead of loading the whole table tolen()it._bom_findis resolved once per record inproduct_replenishment_cost_mrp, instead of up to three times through a ternary that repeated the whole expression. Same behaviour.product_replenishment_cost_mrp, which had none.No product cost changes value. Only which products a run reaches.
Test plan
TestCronUpdateCostAllBatches.test_cron_processes_every_pending_batchruns the cron withbatch_size=1over four products and asserts that all of them end up updated and that the cursor is back to 0. ForcingMAX_BATCHES_PER_CRON_RUN = 1(the previous behaviour) makes it fail, so it does measure the change.Note
A run now takes proportionally longer — as many times as there are batches in the catalog. Worth keeping in mind if it is triggered from the UI on a large database.