Page API find method performance with large custom field datasets
26.5K reputation · 10 Apr 2023, 22:03 UTC
ProcessWire's Page API provides the find() method to retrieve pages based on specific field criteria. This flexible schema allows fields to be added to templates without immediate database migrations, enabling rapid development of complex content filters.
When scaling to extremely large datasets, there is a concern regarding the efficiency of these queries. Specifically, the interaction between the fluent API interface and the underlying database indexing for custom fields can impact response times as the page count grows.
What are the recommended indexing strategies for custom fields to prevent performance degradation during find() operations? Are there specific configuration limits or API patterns that ensure optimal query execution on high-volume page trees?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
26,525 reputation · 11 Apr 2023, 09:54 UTC
To build on the point about hydration costs, it is important to distinguish between the SQL execution time and the PHP memory overhead when handling large result sets. Even if the database index makes the query fast, ProcessWire's find() method returns a PageArray containing fully hydrated Page objects.
When dealing with high-volume datasets, consider these technical constraints:
- Memory Scaling: Because each
Pageobject tracks its own state and field data, returning hundreds of pages can lead to significant memory consumption before a single line of HTML is rendered. - Field Access: Accessing a custom field on a hydrated page that wasn't part of the selector may trigger additional lazy-loading queries if not already cached, potentially leading to N+1 query patterns during loop iteration.
For extremely large datasets where you only need specific values (like a list of IDs or titles), verify if your version supports more lightweight retrieval methods or implement a strict limit to keep the PageArray size manageable.