Database preload operation
Syntax
$objects.preload(
attributes: [...],
fun: list -> ...
)
Description
Loads the specified attributes of a given set of objects from the database with an optimized bulk load and keeps the values in the cache until the given function has been evaluated.
Parameters
name | Type | Type Description | Mandatory | Default |
---|---|---|---|---|
objects | Set of objects | The objects whose attributes are to be loaded. | Yes | - |
attributes | Set of attributes and references | Attributes that are to be loaded on all given objects. | Yes | - |
fun | Function | Function that is evaluated on the input set after the load operation. | yes | - |
Return value
The value calculated by the given function is returned.
Explanation
If the value of an object is queried during a function evaluation, it is possible that the corresponding value has not yet been loaded from the database. In this case, the value is loaded on access. If an operation is executed on many objects, this can lead to a large number of database accesses, which slow down the evaluation. The preload operation can be used to ensure that the load operation is optimized on a large number of objects in advance so that the function evaluation can then take place quickly on the temporarily stored values.