From b8db7a79eefba7f1d9d60415fa197e470d7df74e Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Sat, 14 Dec 2024 05:59:09 -0800 Subject: [PATCH] Cache getPrev() and getNext() ID queries --- CHANGELOG.md | 4 ++++ src/base/Element.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bca5f0f631f..8e8400c92aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft CMS 4 +## Unreleased + +- Fixed a bug where elements’ `getPrev()` and `getNext()` methods could cause duplicate queries. ([#16329](https://github.com/craftcms/cms/discussions/16329)) + ## 4.13.6 - 2024-12-10 - Fixed a bug where blank user group descriptions weren’t getting omitted from project config data. ([#16272](https://github.com/craftcms/cms/pull/16272)) diff --git a/src/base/Element.php b/src/base/Element.php index 757b7c08d62..292936e5fcf 100644 --- a/src/base/Element.php +++ b/src/base/Element.php @@ -5500,7 +5500,7 @@ private function _getRelativeElement(mixed $criteria, int $dir): ?ElementInterfa } /** @var ElementQuery $query */ - $elementIds = $query->ids(); + $elementIds = $query->cache()->ids(); $key = array_search($this->getCanonicalId(), $elementIds, false); if ($key === false || !isset($elementIds[$key + $dir])) {