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 #550
    In the 550th issue of ProcessWire Weekly we're going to check out the latest core updates, introduce a new third party module called PagefileMetadata, and more. Read on!
    Weekly.pw / 23 November 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“Yesterday I sent the client a short documentation for their ProcessWire-powered website. Today all features already used with no questions. #cmsdoneright—Marc Hinse, Web designer/developer