PagesLoader::findMin() method

Minimal find for reduced or delayed overload in some circumstances

This combines the page finding and page loading operation into a single operation and single query, unlike a regular find() which finds matching page IDs in one query and then loads them in a separate query. As a result this method does not need to call the getByIds() method to load pages, as it is able to load them itself.

This strategy may eventually replace the “find() + getByIds()” strategy, but for the moment is only used when the $pages->find() method specifies field=name in the selector. In that selector, name can be any field name, or group of them, i.e. title|date|summary, or a non-existing field like none to specify that no fields should be autojoin (for fastest performance).

Note that while this might reduce overhead in some cases, it can also increase the overall request time if you omit fields that are actually used on the resulting pages. For instance, if the title field is an autojoin field (as it is by default), and we do a $pages->find('template=blog-post, field=none'); and then render a list of blog post titles, then we have just increased overhead because PW would have to perform a separate query to load each blog-post page’s title. On the other hand, if we render a list of blog post titles with date and summary, and the date and summary fields are not configured as autojoin fields, then we can specify all those that we use in our rendered list to greatly improve performance, like this: $pages->find('template=blog-post, field=title|date|summary');.

While this method combines what find() and getById() do in one query, there does not appear to be any overhead benefit when the two strategies are dealing with identical conditions, like the same autojoin fields.

Available since version 3.0.172.

Usage

// basic usage
$items = $pagesLoader->findMin($selector);

// usage with all arguments
$items = $pagesLoader->findMin($selector, array $options = []);

Arguments

NameType(s)Description
selectorstring, array, Selectors
options (optional)array
  • cache (bool): Allow pulling from and saving results to cache? (default=true)
  • joinFields (array): Names of fields to also join into the page load

Return value

Exceptions

Method can throw exceptions on error:

  • WireException


PagesLoader methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #519
    In the 519th issue of ProcessWire Weekly we'll check out a new third party module called RockForms, introduce the latest ProcessWire core updates, and more. Read on!
    Weekly.pw / 20 April 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK