Skip to content

Instantly share code, notes, and snippets.

@ostark
Created February 10, 2021 21:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ostark/f2560ae0664c4cefbd1c3d627bd445d1 to your computer and use it in GitHub Desktop.
Save ostark/f2560ae0664c4cefbd1c3d627bd445d1 to your computer and use it in GitHub Desktop.
lightweight entry queries without custom fields
// Remember old Field service
{% set fieldService = craft.app.get('fields') %}
// Overwrite the service in the container (it will be called later by the EntryQuery)
{% do craft.app.set('fields', 'modules\\NoFields') %}
// Execute the query
{% set result = craft.entries().all() %}
// Restore the original state
{% do craft.app.set('fields', fieldService) %}
<?php
namespace modules;
class NoFields extends \craft\services\Fields
{
public function getAllFields($context = null): array
{
return [];
}
}
@ostark
Copy link
Author

ostark commented Feb 11, 2021

This is a hack to avoid bloated results, if you don't need them, e.g. when displaying Structures with Entries that have tons of fields, but you need the title only.

Why bother?

Error 1038 Out of sort memory, consider increasing sort buffer size

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment