From 9c4d8b3337146e9f35e0b7f110bef9d059236f8b Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 26 Apr 2024 15:38:29 +0200 Subject: [PATCH] perf(db): Sort data for IN before chunking Signed-off-by: Christoph Wurst --- lib/private/Files/Cache/Cache.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 8f0f962a3b7..053856afa4f 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -620,6 +620,9 @@ class Cache implements ICache { $query->delete('filecache') ->whereParentInParameter('parentIds'); + // Sorting before chunking allows the db to find the entries close to each + // other in the index + sort($parentIds, SORT_NUMERIC); foreach (array_chunk($parentIds, 1000) as $parentIdChunk) { $query->setParameter('parentIds', $parentIdChunk, IQueryBuilder::PARAM_INT_ARRAY); $query->execute(); -- 2.39.5