Skip to content

Commit

Permalink
Move query outside the loop and reduce chunk size to 1000
Browse files Browse the repository at this point in the history
This involved changing CacheQueryBuilder\whereParentIn to take a
parameter name, renaming the function accordingly.

Signed-off-by: Sijmen Schoon <[email protected]>
  • Loading branch information
vijfhoek committed Oct 17, 2021
1 parent c959bf2 commit 34600c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions lib/private/Files/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,11 +587,12 @@ private function removeChildren(ICacheEntry $entry) {
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();
}

Expand All @@ -605,11 +606,12 @@ private function removeChildren(ICacheEntry $entry) {
}
}

$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();
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Cache/CacheQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ public function whereParent(int $parent) {
return $this;
}

public function whereParentIn(array $parents) {
public function whereParentInParameter(string $parameter) {
$alias = $this->alias;
if ($alias) {
$alias .= '.';
} else {
$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;
}
Expand Down

0 comments on commit 34600c7

Please sign in to comment.