PagesLoader::preloadFields()
Preload/Prefetch fields for page together as a group (experimental)
This is an optimization that enables you to load the values for multiple fields into
a page at once, and often in a single query. This is similar to the joinFields
option
when loading a page, or the autojoin
option configured with a field, except that it can be used after a page is already loaded. It provides a performance improvement
relative lazy-loading of fields individually as they are accessed.
Preload works only with Fieldtypes that do not override the core’s loading methods. Preload also does not work with FieldtypeMulti types at present, except for the Page
Fieldtype when configured to load a single page. Though it can be enabled for testing
purposes using the useFieldtypeMulti
$options argument.
NOTE: This function is currently experimental, recommended for testing only.
Available since version 3.0.243.
Usage
// basic usage
$array = $pagesLoader->preloadFields(Page $page, array $fieldNames);
// usage with all arguments
$array = $pagesLoader->preloadFields(Page $page, array $fieldNames, array $options = []);
Arguments
Name | Type(s) | Description |
---|---|---|
$page | Page | Page to preload fields for |
$fieldNames | array | Names of fields to preload |
$options (optional) | array |
|
Return value
array
Array containing what was loaded and skipped
PagesLoader methods and properties
API reference based on ProcessWire core version 3.0.251