Question
There is a simple table. It contains nomenclature. There are already about 18,000 rows (so many that users do not search for and enter standard positions immediately), meaning many have a quantity of 0 in stock. There are many calculated fields. I can't recalculate more than 500 rows due to memory limitations. How can I resolve this situation?
Answer
You can manually recalculate, 500 rows at a time, but it's quite challenging (and sometimes there are tables with 100 million rows, which you definitely can't recalculate manually).
For such tasks, a one-time Cron is created.
We will need a field where we will record the maximum id up to which we have recalculated. I will create it directly in the Crons table ā h_store_num
(you can place it anywhere else)
In the crons table, create a cron job:
a1=: reCalculate(table: 'your_table'; where: 'id' = $list)
~list: selectList(table: 'your_table'; field: 'id'; where: 'id' > #h_store_num; limit: 100; order: 'id' asc)
a2=: set(table: $#ntn; field: 'h_store_num' = $last_num)
last_num: $cut[0]
cut: listCut(list: $list; cut: "first"; num: -1)
a3=: if(condition: $list = $#lc; then: $set_off)
set_off: set(table: $#ntn; field: 'status' = false; where: 'id' = #id)
Important points:
The number of rows to recalculate is set in the limit
of the selectList
function
selectList
must have an order
The line with selectList must be fixed with ~
Set the Cron interval so that they definitely do not overlap with the previous one (the minimum interval for cron is 1 minute, but maybe you should make it 5) or check the Overlap Control box.
In a3=: the cron is set to disable when it reaches the end of the table