Skip to content

Commit

Permalink
Merge pull request #32304 from owncloud/stable10_pr31957
Browse files Browse the repository at this point in the history
[stable10] Dont UPDATE SET twice with filecache, use UPDATE SET CASE instead
  • Loading branch information
Vincent Petry committed Aug 21, 2018
2 parents 13efb13 + 5588ee4 commit babbc2a
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions lib/private/Files/Cache/Propagator.php
Expand Up @@ -83,23 +83,22 @@ public function propagateChange($internalPath, $time, $sizeDifference = 0) {

$builder->update('filecache')
->set('mtime', $builder->createFunction('GREATEST(`mtime`, ' . $builder->createNamedParameter($time, IQueryBuilder::PARAM_INT) . ')'))
->set('etag', $builder->createNamedParameter($etag, IQueryBuilder::PARAM_STR))
->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->andWhere($builder->expr()->in('path_hash', $hashParams));

$builder->execute();
->set('etag', $builder->createNamedParameter($etag, IQueryBuilder::PARAM_STR));

if ($sizeDifference !== 0) {
// we need to do size separably so we can ignore entries with uncalculated size
$builder = $this->connection->getQueryBuilder();
$builder->update('filecache')
->set('size', $builder->createFunction('`size` + ' . $builder->createNamedParameter($sizeDifference)))
->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->andWhere($builder->expr()->in('path_hash', $hashParams))
->andWhere($builder->expr()->gt('size', $builder->expr()->literal(-1, IQueryBuilder::PARAM_INT)));

$builder->execute();
// if we need to update size, only update the records with calculated size (>-1)
$builder->set('size', $builder->createFunction('CASE' .
' WHEN ' . $builder->expr()->gt('size', $builder->expr()->literal(-1, IQueryBuilder::PARAM_INT)) .
' THEN `size` + ' . $builder->createNamedParameter($sizeDifference) .
' ELSE `size`' .
' END'
));
}

$builder->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
$builder->andWhere($builder->expr()->in('path_hash', $hashParams));

$builder->execute();
}

protected function getParents($path) {
Expand Down

0 comments on commit babbc2a

Please sign in to comment.