target audience

Written by

in

Optimizing getResources requires a strategic mix of strict parameters, precise caching, and schema limitation. In content management platforms like MODX Revolution where getResources is heavily used for data listing, poor configuration causes massive database bottlenecks and extreme latency. 1. Leverage Aggressive Caching

By default, snippets can evaluate on every page load if forced to run uncached.

Call cached snippets: Always call the snippet using [[getResources?…]] instead of the uncached [[!getResources?…]] unless real-time calculations are required.

Segment data storage: For highly dynamic sections, wrap the call inside a custom caching extra (like getCache) so you only refresh data at specified, elongated intervals. 2. Limit Fields and Unbind Unused Data

Fetching data you do not intend to render degrades processing speed.

Turn off TV processing: Set &includeTVs= to 0 unless Template Variables are strictly required to build the specific list.

Disable content extraction: Set &includeContent= to 0 to prevent the database from pulling heavy content blobs into the memory buffer.

Select selective fields: Use the &select parameter to fetch only the explicit database fields (e.g., id, pagetitle, uri) required by your chunk. 3. Restrict Query Scopes

Broad lookups force full-table scans that completely choke large databases.

Enforce hard boundaries: Always use the &limit= parameter to keep result counts small (e.g., &limit=10).

Bind specific parents: Explicitly declare &parents= to keep the scanner scoped inside narrow directory trees instead of traversing the entire root layout.

Avoid deep recursion: Set &depth= to 1 or 2 at most to control how deeply nested the resource crawler travels down the tree. 4. Optimize the Render Tree (Chunks)

The chunk template that parses each item dictates a major portion of execution time.

Sanitize inner logic: Do not call uncached snippets, heavy output filters, or nested resource-fetching calls inside the chunk template.

Pre-render assets: Handle conditional logic or heavy markup changes inside a standalone, compiled custom snippet before feeding properties to the renderer. Migration Checklist: If Performance Continues to Stall

Consider replacing getResources with pdoResources (part of the pdoTools suite). It shares identical parameters but queries the database significantly faster via optimized PDO joining mechanisms, completely bypassing the heavy xPDO instantiation layer.

If you would like to pinpoint your system bottlenecks, tell me:

What specific content management system or framework version you are currently using? Roughly how many records exist in your database table?

Can you share the current code snippet parameters causing the speed lag? Caching Guidelines for MODX Revolution – Mark Hamstra

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *