]> source.dussan.org Git - nextcloud-server.git/commitdiff
Move query outside the loop and reduce chunk size to 1000 29507/head
authorSijmen Schoon <me@sijmenschoon.nl>
Sun, 17 Oct 2021 18:52:38 +0000 (20:52 +0200)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Mon, 1 Nov 2021 11:27:36 +0000 (11:27 +0000)
This involved changing CacheQueryBuilder\whereParentIn to take a
parameter name, renaming the function accordingly.

Signed-off-by: Sijmen Schoon <me@sijmenschoon.nl>
lib/private/Files/Cache/Cache.php
lib/private/Files/Cache/CacheQueryBuilder.php

index 7e3cfcfda5d7c1c24152e93bfdb63fcc78a805a0..34ed6d33a2d8c34d9627a6e1c8e07a1c559c1334 100644 (file)
@@ -585,11 +585,12 @@ class Cache implements ICache {
                                return $cacheEntry->getId();
                        }, $children);
 
-                       $childIdChunks = array_chunk($childIds, 2048);
-                       foreach ($childIdChunks as $childIdChunk) {
-                               $query = $this->getQueryBuilder();
-                               $query->delete('filecache_extended')
-                                       ->where($query->expr()->in('fileid', $query->createNamedParameter($childIdChunk, IQueryBuilder::PARAM_INT_ARRAY)));
+                       $query = $this->getQueryBuilder();
+                       $query->delete('filecache_extended')
+                               ->where($query->expr()->in('fileid', $query->createParameter('childIds')));
+                       
+                       foreach (array_chunk($childIds, 1000) as $childIdChunk) {
+                               $query->setParameter('childIds', $childIdChunk, IQueryBuilder::PARAM_INT_ARRAY);
                                $query->execute();
                        }
 
@@ -603,11 +604,12 @@ class Cache implements ICache {
                        }
                }
 
-               $parentIdChunks = array_chunk($parentIds, 2048);
-               foreach ($parentIdChunks as $parentIdChunk) {
-                       $query = $this->getQueryBuilder();
-                       $query->delete('filecache')
-                               ->whereParentIn($parentIdChunk);
+               $query = $this->getQueryBuilder();
+               $query->delete('filecache')
+                       ->whereParentInParameter('parentIds');
+
+               foreach (array_chunk($parentIds, 1000) as $parentIdChunk) {
+                       $query->setParameter('parentIds', $parentIdChunk, IQueryBuilder::PARAM_INT_ARRAY);
                        $query->execute();
                }
        }
index ac17cfaffb2343de5cc332646bd3cdbe25b71826..2215cef9a15a050a0ec00612a85295ff373d0cb6 100644 (file)
@@ -95,7 +95,7 @@ class CacheQueryBuilder extends QueryBuilder {
                return $this;
        }
 
-       public function whereParentIn(array $parents) {
+       public function whereParentInParameter(string $parameter) {
                $alias = $this->alias;
                if ($alias) {
                        $alias .= '.';
@@ -103,7 +103,7 @@ class CacheQueryBuilder extends QueryBuilder {
                        $alias = '';
                }
 
-               $this->andWhere($this->expr()->in("{$alias}parent", $this->createNamedParameter($parents, IQueryBuilder::PARAM_INT_ARRAY)));
+               $this->andWhere($this->expr()->in("{$alias}parent", $this->createParameter($parameter)));
 
                return $this;
        }