Skip to content

Commit

Permalink
Close cursor early in calculateFolderSize
Browse files Browse the repository at this point in the history
This method triggers additional queries in $this->update() so to avoid
potential database locks or delays, we close the cursor as soon as it is not needed any more
  • Loading branch information
Vincent Petry authored and MorrisJobke committed Jan 29, 2015
1 parent 80560e7 commit 234f33e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/private/files/cache/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ public function calculateFolderSize($path, $entry = null) {
'WHERE `parent` = ? AND `storage` = ?';
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
if ($row = $result->fetchRow()) {
$result->closeCursor();
list($sum, $min, $unencryptedSum) = array_values($row);
$sum = 0 + $sum;
$min = 0 + $min;
Expand All @@ -562,6 +563,8 @@ public function calculateFolderSize($path, $entry = null) {
if ($totalSize !== -1 and $unencryptedSum > 0) {
$totalSize = $unencryptedSum;
}
} else {
$result->closeCursor();
}
}
return $totalSize;
Expand Down
1 change: 1 addition & 0 deletions lib/private/files/cache/homecache.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function calculateFolderSize($path, $entry = null) {
'WHERE `parent` = ? AND `storage` = ? AND `size` >= 0';
$result = \OC_DB::executeAudited($sql, array($id, $this->getNumericStorageId()));
if ($row = $result->fetchRow()) {
$result->closeCursor();
list($sum, $unencryptedSum) = array_values($row);
$totalSize = 0 + $sum;
$unencryptedSize = 0 + $unencryptedSum;
Expand Down

0 comments on commit 234f33e

Please sign in to comment.