Skip to content

Commit 9cf374c

Browse files
committed
Make default query limit configurable via query_default_limit
The default limit of 20 for content queries ({% setcontent %} and the query DSL) was hardcoded in ContentQueryParser. Read it from the new general/query_default_limit config key, falling back to 20 so existing behavior is unchanged when the key is unset. Adds a documented key in config/bolt/config.yaml and a yaml-migration to add it to existing installations.
1 parent f3f3073 commit 9cf374c

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

config/bolt/config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ query_search:
152152
# example in `type: select`.
153153
maximum_listing_select: 50000
154154

155+
# Default number of records returned by a content query (e.g. `{% setcontent %}`
156+
# or the query DSL) when no explicit `limit` is given. This guards against
157+
# unintentionally fetching an entire ContentType. Override per query with
158+
# `limit`, e.g. `{% setcontent pages limit 30 %}`.
159+
query_default_limit: 20
160+
155161
# Template for showing the search results. If not defined, uses the settings for
156162
# listing_template and listing_records.
157163
#

src/Storage/ContentQueryParser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ protected function parseOperation(): void
181181
*/
182182
protected function parseDirectives(): void
183183
{
184-
// If the user doesn't pass in a limit, we'll get 20. Don't break the site by fetching _all_.
185-
$this->directives = ['limit' => 20];
184+
// If the user doesn't pass in a limit, we fall back to the configured
185+
// default (20). Don't break the site by fetching _all_.
186+
$this->directives = ['limit' => $this->config->get('general/query_default_limit', 20)];
186187

187188
if (! $this->params) {
188189
return;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Add the configurable default limit for content queries (`{% setcontent %}`
2+
# and the query DSL). Previously hardcoded to 20 in ContentQueryParser.
3+
file: bolt/config.yaml
4+
since: 6.2.0
5+
6+
add:
7+
query_default_limit: 20

0 commit comments

Comments
 (0)