{recompute:item_ids:fields_ids}

Description

Recomputes the computed fields on one or more items, as if those items had just been saved. A computed field is a slice field whose value is generated by an expression (its Computed insert/update function) - a counter, a slug, a cached total, an aggregate of related items. recompute re-runs those expressions and writes the fresh values back. It is most often placed inside another item own computed field, so that saving item A also refreshes a derived value on related item B (recompute a parent link count, refresh a cached sum, propagate a change down a relation). recompute produces no visible output: it returns an empty string and does its work as a side effect. The first argument is a dash-separated list of item long ids; empty entries and ids with no matching item are skipped. The optional second argument is a dash-separated list of field ids that limits the recompute to those fields - otherwise every computed field on the item is refreshed.

Parameters

item_ids required default (empty - no item, nothing happens)

Dash-separated list of long item ids whose computed fields will be recomputed. Empty entries are skipped, and an id that points to no existing item is silently ignored.

fields_ids optional default (empty - recompute every computed field)

Optional dash-separated list of field ids to restrict the recompute to. When given, only those fields are refreshed. When empty, every computed field on the item is refreshed.

Examples

test[{recompute:}]
Expected[]
Actual[]
With no item id there is nothing to recompute. The command does nothing and returns an empty string.
test[{recompute:00000000000000000000000000000000}]
Expected[]
Actual[]
An id that points to no existing item is silently ignored. Safe to call without first checking the item exists.
test[{recompute:5726c2c6b035d7aab450d1794e9e90d7}]
Expected[]
Actual[]
Recomputes every computed field on the item with this long id, exactly as if the item had just been saved. The output is always empty - the work is the side effect. This fixture has no computed fields, so nothing changes here, but the call is real.
test[{recompute:5726c2c6b035d7aab450d1794e9e90d7:integer.........}]
Expected[]
Actual[]
The optional second list restricts the recompute to the named field ids. Here only the field integer......... would be refreshed; all other computed fields are left untouched.
test[{recompute:5726c2c6b035d7aab450d1794e9e90d7-a65d19971986e750761f0efcd9a16b1b}]
Expected[]
Actual[]
Item ids are dash-separated, so one call can refresh many items (here two fixture items). Each is loaded and recomputed in turn.
virtual{recompute:{relation.......9}}
Expected()
The real use: place recompute inside one item own computed field so that saving this item also refreshes a derived value on each related item. Here {relation.......9} expands to the related items long ids and each is recomputed. A common variant recomputes one named field across a whole slice, for example {recompute:{ids:SLICE_ID}:fieldid.........}. Output is always empty.