diff options
author | Vincent Petry <vincent@nextcloud.com> | 2022-08-17 12:36:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-17 12:36:16 +0300 |
commit | 312b719acf686f51065e83290cd88704d703a50c (patch) | |
tree | d35436952d0fa21a5010f53944c97a73bd81be7b /lib | |
parent | 11d5a1d3dfea09dc53894d51e336c512e75f733d (diff) | |
parent | de63f6363f1ae590c9735fbe9592835c04ab32cd (diff) |
Merge pull request #32943 from nextcloud/unencrypted-size-revert-interface-changes
Revert interface changes from "store unencrypted size in the unencrypted_size column"
Diffstat (limited to 'lib')
12 files changed, 161 insertions, 181 deletions
diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php index 333984bde71..ae4f19f5d18 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/ExpressionBuilder.php @@ -114,12 +114,12 @@ class ExpressionBuilder implements IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string */ - public function comparison($x, string $operator, $y, $type = null): IQueryFunction { + public function comparison($x, string $operator, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); - return new QueryFunction($this->expressionBuilder->comparison($x, $operator, $y)); + return $this->expressionBuilder->comparison($x, $operator, $y); } /** @@ -137,12 +137,12 @@ class ExpressionBuilder implements IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string */ - public function eq($x, $y, $type = null): IQueryFunction { + public function eq($x, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); - return new QueryFunction($this->expressionBuilder->eq($x, $y)); + return $this->expressionBuilder->eq($x, $y); } /** @@ -159,12 +159,12 @@ class ExpressionBuilder implements IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string */ - public function neq($x, $y, $type = null): IQueryFunction { + public function neq($x, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); - return new QueryFunction($this->expressionBuilder->neq($x, $y)); + return $this->expressionBuilder->neq($x, $y); } /** @@ -181,12 +181,12 @@ class ExpressionBuilder implements IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string */ - public function lt($x, $y, $type = null): IQueryFunction { + public function lt($x, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); - return new QueryFunction($this->expressionBuilder->lt($x, $y)); + return $this->expressionBuilder->lt($x, $y); } /** @@ -203,12 +203,12 @@ class ExpressionBuilder implements IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string */ - public function lte($x, $y, $type = null): IQueryFunction { + public function lte($x, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); - return new QueryFunction($this->expressionBuilder->lte($x, $y)); + return $this->expressionBuilder->lte($x, $y); } /** @@ -225,12 +225,12 @@ class ExpressionBuilder implements IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string */ - public function gt($x, $y, $type = null): IQueryFunction { + public function gt($x, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); - return new QueryFunction($this->expressionBuilder->gt($x, $y)); + return $this->expressionBuilder->gt($x, $y); } /** @@ -247,12 +247,12 @@ class ExpressionBuilder implements IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string */ - public function gte($x, $y, $type = null): IQueryFunction { + public function gte($x, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); - return new QueryFunction($this->expressionBuilder->gte($x, $y)); + return $this->expressionBuilder->gte($x, $y); } /** @@ -260,11 +260,11 @@ class ExpressionBuilder implements IExpressionBuilder { * * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be restricted by IS NULL. * - * @return IQueryFunction + * @return string */ - public function isNull($x): IQueryFunction { + public function isNull($x): string { $x = $this->helper->quoteColumnName($x); - return new QueryFunction($this->expressionBuilder->isNull($x)); + return $this->expressionBuilder->isNull($x); } /** @@ -272,11 +272,11 @@ class ExpressionBuilder implements IExpressionBuilder { * * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be restricted by IS NOT NULL. * - * @return IQueryFunction + * @return string */ - public function isNotNull($x): IQueryFunction { + public function isNotNull($x): string { $x = $this->helper->quoteColumnName($x); - return new QueryFunction($this->expressionBuilder->isNotNull($x)); + return $this->expressionBuilder->isNotNull($x); } /** @@ -287,12 +287,12 @@ class ExpressionBuilder implements IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string */ - public function like($x, $y, $type = null): IQueryFunction { + public function like($x, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); - return new QueryFunction($this->expressionBuilder->like($x, $y)); + return $this->expressionBuilder->like($x, $y); } /** @@ -303,11 +303,11 @@ class ExpressionBuilder implements IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string * @since 9.0.0 */ - public function iLike($x, $y, $type = null): IQueryFunction { - return new QueryFunction($this->expressionBuilder->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y))); + public function iLike($x, $y, $type = null): string { + return $this->expressionBuilder->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y)); } /** @@ -318,12 +318,12 @@ class ExpressionBuilder implements IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string */ - public function notLike($x, $y, $type = null): IQueryFunction { + public function notLike($x, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); - return new QueryFunction($this->expressionBuilder->notLike($x, $y)); + return $this->expressionBuilder->notLike($x, $y); } /** @@ -334,12 +334,12 @@ class ExpressionBuilder implements IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string */ - public function in($x, $y, $type = null): IQueryFunction { + public function in($x, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnNames($y); - return new QueryFunction($this->expressionBuilder->in($x, $y)); + return $this->expressionBuilder->in($x, $y); } /** @@ -350,34 +350,34 @@ class ExpressionBuilder implements IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string */ - public function notIn($x, $y, $type = null): IQueryFunction { + public function notIn($x, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnNames($y); - return new QueryFunction($this->expressionBuilder->notIn($x, $y)); + return $this->expressionBuilder->notIn($x, $y); } /** * Creates a $x = '' statement, because Oracle needs a different check * * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be inspected by the comparison. - * @return IQueryFunction + * @return string * @since 13.0.0 */ - public function emptyString($x): IQueryFunction { - return new QueryFunction($this->eq($x, $this->literal('', IQueryBuilder::PARAM_STR))); + public function emptyString($x): string { + return $this->eq($x, $this->literal('', IQueryBuilder::PARAM_STR)); } /** * Creates a `$x <> ''` statement, because Oracle needs a different check * * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be inspected by the comparison. - * @return IQueryFunction + * @return string * @since 13.0.0 */ - public function nonEmptyString($x): IQueryFunction { - return new QueryFunction($this->neq($x, $this->literal('', IQueryBuilder::PARAM_STR))); + public function nonEmptyString($x): string { + return $this->neq($x, $this->literal('', IQueryBuilder::PARAM_STR)); } /** diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php index 74209d0c3da..3bb54d4b26e 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/MySqlExpressionBuilder.php @@ -49,10 +49,10 @@ class MySqlExpressionBuilder extends ExpressionBuilder { /** * @inheritdoc */ - public function iLike($x, $y, $type = null): IQueryFunction { + public function iLike($x, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); - return new QueryFunction($this->expressionBuilder->comparison($x, ' COLLATE ' . $this->collation . ' LIKE', $y)); + return $this->expressionBuilder->comparison($x, ' COLLATE ' . $this->collation . ' LIKE', $y); } /** diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php index 20d68b30b33..f9b58d7d8ed 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/OCIExpressionBuilder.php @@ -49,101 +49,101 @@ class OCIExpressionBuilder extends ExpressionBuilder { /** * @inheritdoc */ - public function comparison($x, string $operator, $y, $type = null): IQueryFunction { + public function comparison($x, string $operator, $y, $type = null): string { $x = $this->prepareColumn($x, $type); $y = $this->prepareColumn($y, $type); - return new QueryFunction($this->expressionBuilder->comparison($x, $operator, $y)); + return $this->expressionBuilder->comparison($x, $operator, $y); } /** * @inheritdoc */ - public function eq($x, $y, $type = null): IQueryFunction { + public function eq($x, $y, $type = null): string { $x = $this->prepareColumn($x, $type); $y = $this->prepareColumn($y, $type); - return new QueryFunction($this->expressionBuilder->eq($x, $y)); + return $this->expressionBuilder->eq($x, $y); } /** * @inheritdoc */ - public function neq($x, $y, $type = null): IQueryFunction { + public function neq($x, $y, $type = null): string { $x = $this->prepareColumn($x, $type); $y = $this->prepareColumn($y, $type); - return new QueryFunction($this->expressionBuilder->neq($x, $y)); + return $this->expressionBuilder->neq($x, $y); } /** * @inheritdoc */ - public function lt($x, $y, $type = null): IQueryFunction { + public function lt($x, $y, $type = null): string { $x = $this->prepareColumn($x, $type); $y = $this->prepareColumn($y, $type); - return new QueryFunction($this->expressionBuilder->lt($x, $y)); + return $this->expressionBuilder->lt($x, $y); } /** * @inheritdoc */ - public function lte($x, $y, $type = null): IQueryFunction { + public function lte($x, $y, $type = null): string { $x = $this->prepareColumn($x, $type); $y = $this->prepareColumn($y, $type); - return new QueryFunction($this->expressionBuilder->lte($x, $y)); + return $this->expressionBuilder->lte($x, $y); } /** * @inheritdoc */ - public function gt($x, $y, $type = null): IQueryFunction { + public function gt($x, $y, $type = null): string { $x = $this->prepareColumn($x, $type); $y = $this->prepareColumn($y, $type); - return new QueryFunction($this->expressionBuilder->gt($x, $y)); + return $this->expressionBuilder->gt($x, $y); } /** * @inheritdoc */ - public function gte($x, $y, $type = null): IQueryFunction { + public function gte($x, $y, $type = null): string { $x = $this->prepareColumn($x, $type); $y = $this->prepareColumn($y, $type); - return new QueryFunction($this->expressionBuilder->gte($x, $y)); + return $this->expressionBuilder->gte($x, $y); } /** * @inheritdoc */ - public function in($x, $y, $type = null): IQueryFunction { + public function in($x, $y, $type = null): string { $x = $this->prepareColumn($x, $type); $y = $this->prepareColumn($y, $type); - return new QueryFunction($this->expressionBuilder->in($x, $y)); + return $this->expressionBuilder->in($x, $y); } /** * @inheritdoc */ - public function notIn($x, $y, $type = null): IQueryFunction { + public function notIn($x, $y, $type = null): string { $x = $this->prepareColumn($x, $type); $y = $this->prepareColumn($y, $type); - return new QueryFunction($this->expressionBuilder->notIn($x, $y)); + return $this->expressionBuilder->notIn($x, $y); } /** * Creates a $x = '' statement, because Oracle needs a different check * * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be inspected by the comparison. - * @return IQueryFunction + * @return string * @since 13.0.0 */ - public function emptyString($x): IQueryFunction { + public function emptyString($x): string { return $this->isNull($x); } @@ -151,10 +151,10 @@ class OCIExpressionBuilder extends ExpressionBuilder { * Creates a `$x <> ''` statement, because Oracle needs a different check * * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be inspected by the comparison. - * @return IQueryFunction + * @return string * @since 13.0.0 */ - public function nonEmptyString($x): IQueryFunction { + public function nonEmptyString($x): string { return $this->isNotNull($x); } @@ -182,14 +182,14 @@ class OCIExpressionBuilder extends ExpressionBuilder { /** * @inheritdoc */ - public function like($x, $y, $type = null): IQueryFunction { - return new QueryFunction(parent::like($x, $y, $type) . " ESCAPE '\\'"); + public function like($x, $y, $type = null): string { + return parent::like($x, $y, $type) . " ESCAPE '\\'"; } /** * @inheritdoc */ - public function iLike($x, $y, $type = null): IQueryFunction { + public function iLike($x, $y, $type = null): string { return $this->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y)); } } diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/PgSqlExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/PgSqlExpressionBuilder.php index cbebe97ae87..0fba5363a28 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/PgSqlExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/PgSqlExpressionBuilder.php @@ -52,9 +52,9 @@ class PgSqlExpressionBuilder extends ExpressionBuilder { /** * @inheritdoc */ - public function iLike($x, $y, $type = null): IQueryFunction { + public function iLike($x, $y, $type = null): string { $x = $this->helper->quoteColumnName($x); $y = $this->helper->quoteColumnName($y); - return new QueryFunction($this->expressionBuilder->comparison($x, 'ILIKE', $y)); + return $this->expressionBuilder->comparison($x, 'ILIKE', $y); } } diff --git a/lib/private/DB/QueryBuilder/ExpressionBuilder/SqliteExpressionBuilder.php b/lib/private/DB/QueryBuilder/ExpressionBuilder/SqliteExpressionBuilder.php index 5425138fa6c..289aa09b003 100644 --- a/lib/private/DB/QueryBuilder/ExpressionBuilder/SqliteExpressionBuilder.php +++ b/lib/private/DB/QueryBuilder/ExpressionBuilder/SqliteExpressionBuilder.php @@ -23,18 +23,15 @@ */ namespace OC\DB\QueryBuilder\ExpressionBuilder; -use OC\DB\QueryBuilder\QueryFunction; -use OCP\DB\QueryBuilder\IQueryFunction; - class SqliteExpressionBuilder extends ExpressionBuilder { /** * @inheritdoc */ - public function like($x, $y, $type = null): IQueryFunction { - return new QueryFunction(parent::like($x, $y, $type) . " ESCAPE '\\'"); + public function like($x, $y, $type = null): string { + return parent::like($x, $y, $type) . " ESCAPE '\\'"; } - public function iLike($x, $y, $type = null): IQueryFunction { - return new QueryFunction($this->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y), $type)); + public function iLike($x, $y, $type = null): string { + return $this->like($this->functionBuilder->lower($x), $this->functionBuilder->lower($y), $type); } } diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php index 408a879d624..e0a7549a0ad 100644 --- a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php +++ b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php @@ -121,15 +121,4 @@ class FunctionBuilder implements IFunctionBuilder { public function least($x, $y): IQueryFunction { return new QueryFunction('LEAST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')'); } - - public function case(array $whens, $else): IQueryFunction { - if (count($whens) < 1) { - return new QueryFunction($this->helper->quoteColumnName($else)); - } - - $whenParts = array_map(function (array $when) { - return 'WHEN ' . $this->helper->quoteColumnName($when['when']) . ' THEN ' . $this->helper->quoteColumnName($when['then']); - }, $whens); - return new QueryFunction('CASE ' . implode(' ', $whenParts) . ' ELSE ' . $this->helper->quoteColumnName($else) . ' END'); - } } diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php index d991cbd1dd5..e81ba61b3a7 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -715,12 +715,11 @@ class QueryBuilder implements IQueryBuilder { * @param string $fromAlias The alias that points to a from clause. * @param string $join The table name to join. * @param string $alias The alias of the join table. - * @param string|IQueryFunction|ICompositeExpression|null $condition The condition for the join. + * @param string|ICompositeExpression|null $condition The condition for the join. * * @return $this This QueryBuilder instance. */ public function join($fromAlias, $join, $alias, $condition = null) { - $condition = $condition !== null ? (string)$condition : null; $this->queryBuilder->join( $this->quoteAlias($fromAlias), $this->getTableName($join), @@ -744,12 +743,11 @@ class QueryBuilder implements IQueryBuilder { * @param string $fromAlias The alias that points to a from clause. * @param string $join The table name to join. * @param string $alias The alias of the join table. - * @param string|IQueryFunction|ICompositeExpression|null $condition The condition for the join. + * @param string|ICompositeExpression|null $condition The condition for the join. * * @return $this This QueryBuilder instance. */ public function innerJoin($fromAlias, $join, $alias, $condition = null) { - $condition = $condition !== null ? (string)$condition : null; $this->queryBuilder->innerJoin( $this->quoteAlias($fromAlias), $this->getTableName($join), @@ -773,12 +771,11 @@ class QueryBuilder implements IQueryBuilder { * @param string $fromAlias The alias that points to a from clause. * @param string $join The table name to join. * @param string $alias The alias of the join table. - * @param string|IQueryFunction|ICompositeExpression|null $condition The condition for the join. + * @param string|ICompositeExpression|null $condition The condition for the join. * * @return $this This QueryBuilder instance. */ public function leftJoin($fromAlias, $join, $alias, $condition = null) { - $condition = $condition !== null ? (string)$condition : null; $this->queryBuilder->leftJoin( $this->quoteAlias($fromAlias), $this->getTableName($join), @@ -802,12 +799,11 @@ class QueryBuilder implements IQueryBuilder { * @param string $fromAlias The alias that points to a from clause. * @param string $join The table name to join. * @param string $alias The alias of the join table. - * @param string|IQueryFunction|ICompositeExpression|null $condition The condition for the join. + * @param string|ICompositeExpression|null $condition The condition for the join. * * @return $this This QueryBuilder instance. */ public function rightJoin($fromAlias, $join, $alias, $condition = null) { - $condition = $condition !== null ? (string)$condition : null; $this->queryBuilder->rightJoin( $this->quoteAlias($fromAlias), $this->getTableName($join), diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index f23635aa01b..ec284282178 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -875,26 +875,32 @@ class Cache implements ICache { $id = $entry['fileid']; $query = $this->getQueryBuilder(); - $query->selectAlias($query->func()->sum('size'), 'size_sum') - ->selectAlias($query->func()->min('size'), 'size_min') - // in case of encryption being enabled after some files are already uploaded, some entries will have an unencrypted_size of 0 and a non-zero size - ->selectAlias($query->func()->sum( - $query->func()->case([ - ['when' => $query->expr()->eq('unencrypted_size', $query->expr()->literal(0, IQueryBuilder::PARAM_INT)), 'then' => 'size'], - ], 'unencrypted_size') - ), 'unencrypted_sum') - ->selectAlias($query->func()->min('unencrypted_size'), 'unencrypted_min') - ->selectAlias($query->func()->max('unencrypted_size'), 'unencrypted_max') + $query->select('size', 'unencrypted_size') ->from('filecache') - ->whereStorageId($this->getNumericStorageId()) ->whereParent($id); $result = $query->execute(); - $row = $result->fetch(); + $rows = $result->fetchAll(); $result->closeCursor(); - if ($row) { - ['size_sum' => $sum, 'size_min' => $min, 'unencrypted_sum' => $unencryptedSum, 'unencrypted_min' => $unencryptedMin, 'unencrypted_max' => $unencryptedMax] = $row; + if ($rows) { + $sizes = array_map(function (array $row) { + return (int)$row['size']; + }, $rows); + $unencryptedOnlySizes = array_map(function (array $row) { + return (int)$row['unencrypted_size']; + }, $rows); + $unencryptedSizes = array_map(function (array $row) { + return (int)(($row['unencrypted_size'] > 0) ? $row['unencrypted_size'] : $row['size']); + }, $rows); + + $sum = array_sum($sizes); + $min = min($sizes); + + $unencryptedSum = array_sum($unencryptedSizes); + $unencryptedMin = min($unencryptedSizes); + $unencryptedMax = max($unencryptedOnlySizes); + $sum = 0 + $sum; $min = 0 + $min; if ($min === -1) { @@ -907,18 +913,22 @@ class Cache implements ICache { } else { $unencryptedTotal = $unencryptedSum; } - if ($entry['size'] !== $totalSize) { - // only set unencrypted size for a folder if any child entries have it set - if ($unencryptedMax > 0) { - $this->update($id, [ - 'size' => $totalSize, - 'unencrypted_size' => $unencryptedTotal, - ]); - } else { - $this->update($id, [ - 'size' => $totalSize, - ]); - } + } else { + $totalSize = 0; + $unencryptedTotal = 0; + $unencryptedMax = 0; + } + if ($entry['size'] !== $totalSize) { + // only set unencrypted size for a folder if any child entries have it set, or the folder is empty + if ($unencryptedMax > 0 || $totalSize === 0) { + $this->update($id, [ + 'size' => $totalSize, + 'unencrypted_size' => $unencryptedTotal, + ]); + } else { + $this->update($id, [ + 'size' => $totalSize, + ]); } } } diff --git a/lib/private/Files/Cache/Propagator.php b/lib/private/Files/Cache/Propagator.php index a0953baa785..2909e998bf9 100644 --- a/lib/private/Files/Cache/Propagator.php +++ b/lib/private/Files/Cache/Propagator.php @@ -116,18 +116,18 @@ class Propagator implements IPropagator { if ($this->storage->instanceOfStorage(Encryption::class)) { // in case of encryption being enabled after some files are already uploaded, some entries will have an unencrypted_size of 0 and a non-zero size + $eq = $builder->expr()->eq('unencrypted_size', $builder->expr()->literal(0, IQueryBuilder::PARAM_INT)); + $sizeColumn = $builder->getColumnName('size'); + $unencryptedSizeColumn = $builder->getColumnName('unencrypted_size'); $builder->set('unencrypted_size', $builder->func()->greatest( $builder->func()->add( - $builder->func()->case([ - ['when' => $builder->expr()->eq('unencrypted_size', $builder->expr()->literal(0, IQueryBuilder::PARAM_INT)), 'then' => 'size'] - ], 'unencrypted_size'), + $builder->createFunction("CASE WHEN $eq THEN $unencryptedSizeColumn ELSE $sizeColumn END"), $builder->createNamedParameter($sizeDifference) ), $builder->createNamedParameter(-1, IQueryBuilder::PARAM_INT) )); } - $a = $builder->getSQL(); $builder->execute(); } } diff --git a/lib/public/DB/QueryBuilder/IExpressionBuilder.php b/lib/public/DB/QueryBuilder/IExpressionBuilder.php index 8f7cd10dee5..53dc1fa5a7f 100644 --- a/lib/public/DB/QueryBuilder/IExpressionBuilder.php +++ b/lib/public/DB/QueryBuilder/IExpressionBuilder.php @@ -107,7 +107,7 @@ interface IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string * @since 8.2.0 - Parameter $type was added in 9.0.0 * * @psalm-taint-sink sql $x @@ -115,7 +115,7 @@ interface IExpressionBuilder { * @psalm-taint-sink sql $y * @psalm-taint-sink sql $type */ - public function comparison($x, string $operator, $y, $type = null): IQueryFunction; + public function comparison($x, string $operator, $y, $type = null): string; /** * Creates an equality comparison expression with the given arguments. @@ -132,14 +132,14 @@ interface IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string * @since 8.2.0 - Parameter $type was added in 9.0.0 * * @psalm-taint-sink sql $x * @psalm-taint-sink sql $y * @psalm-taint-sink sql $type */ - public function eq($x, $y, $type = null): IQueryFunction; + public function eq($x, $y, $type = null): string; /** * Creates a non equality comparison expression with the given arguments. @@ -155,14 +155,14 @@ interface IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string * @since 8.2.0 - Parameter $type was added in 9.0.0 * * @psalm-taint-sink sql $x * @psalm-taint-sink sql $y * @psalm-taint-sink sql $type */ - public function neq($x, $y, $type = null): IQueryFunction; + public function neq($x, $y, $type = null): string; /** * Creates a lower-than comparison expression with the given arguments. @@ -178,14 +178,14 @@ interface IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string * @since 8.2.0 - Parameter $type was added in 9.0.0 * * @psalm-taint-sink sql $x * @psalm-taint-sink sql $y * @psalm-taint-sink sql $type */ - public function lt($x, $y, $type = null): IQueryFunction; + public function lt($x, $y, $type = null): string; /** * Creates a lower-than-equal comparison expression with the given arguments. @@ -201,14 +201,14 @@ interface IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string * @since 8.2.0 - Parameter $type was added in 9.0.0 * * @psalm-taint-sink sql $x * @psalm-taint-sink sql $y * @psalm-taint-sink sql $type */ - public function lte($x, $y, $type = null): IQueryFunction; + public function lte($x, $y, $type = null): string; /** * Creates a greater-than comparison expression with the given arguments. @@ -224,14 +224,14 @@ interface IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string * @since 8.2.0 - Parameter $type was added in 9.0.0 * * @psalm-taint-sink sql $x * @psalm-taint-sink sql $y * @psalm-taint-sink sql $type */ - public function gt($x, $y, $type = null): IQueryFunction; + public function gt($x, $y, $type = null): string; /** * Creates a greater-than-equal comparison expression with the given arguments. @@ -247,38 +247,38 @@ interface IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string * @since 8.2.0 - Parameter $type was added in 9.0.0 * * @psalm-taint-sink sql $x * @psalm-taint-sink sql $y * @psalm-taint-sink sql $type */ - public function gte($x, $y, $type = null): IQueryFunction; + public function gte($x, $y, $type = null): string; /** * Creates an IS NULL expression with the given arguments. * * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be restricted by IS NULL. * - * @return IQueryFunction + * @return string * @since 8.2.0 * * @psalm-taint-sink sql $x */ - public function isNull($x): IQueryFunction; + public function isNull($x): string; /** * Creates an IS NOT NULL expression with the given arguments. * * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be restricted by IS NOT NULL. * - * @return IQueryFunction + * @return string * @since 8.2.0 * * @psalm-taint-sink sql $x */ - public function isNotNull($x): IQueryFunction; + public function isNotNull($x): string; /** * Creates a LIKE() comparison expression with the given arguments. @@ -288,14 +288,14 @@ interface IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string * @since 8.2.0 - Parameter $type was added in 9.0.0 * * @psalm-taint-sink sql $x * @psalm-taint-sink sql $y * @psalm-taint-sink sql $type */ - public function like($x, $y, $type = null): IQueryFunction; + public function like($x, $y, $type = null): string; /** * Creates a NOT LIKE() comparison expression with the given arguments. @@ -305,14 +305,14 @@ interface IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string * @since 8.2.0 - Parameter $type was added in 9.0.0 * * @psalm-taint-sink sql $x * @psalm-taint-sink sql $y * @psalm-taint-sink sql $type */ - public function notLike($x, $y, $type = null): IQueryFunction; + public function notLike($x, $y, $type = null): string; /** * Creates a ILIKE() comparison expression with the given arguments. @@ -322,14 +322,14 @@ interface IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string * @since 9.0.0 * * @psalm-taint-sink sql $x * @psalm-taint-sink sql $y * @psalm-taint-sink sql $type */ - public function iLike($x, $y, $type = null): IQueryFunction; + public function iLike($x, $y, $type = null): string; /** * Creates a IN () comparison expression with the given arguments. @@ -339,14 +339,14 @@ interface IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string * @since 8.2.0 - Parameter $type was added in 9.0.0 * * @psalm-taint-sink sql $x * @psalm-taint-sink sql $y * @psalm-taint-sink sql $type */ - public function in($x, $y, $type = null): IQueryFunction; + public function in($x, $y, $type = null): string; /** * Creates a NOT IN () comparison expression with the given arguments. @@ -356,36 +356,36 @@ interface IExpressionBuilder { * @param mixed|null $type one of the IQueryBuilder::PARAM_* constants * required when comparing text fields for oci compatibility * - * @return IQueryFunction + * @return string * @since 8.2.0 - Parameter $type was added in 9.0.0 * * @psalm-taint-sink sql $x * @psalm-taint-sink sql $y * @psalm-taint-sink sql $type */ - public function notIn($x, $y, $type = null): IQueryFunction; + public function notIn($x, $y, $type = null): string; /** * Creates a $x = '' statement, because Oracle needs a different check * * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be inspected by the comparison. - * @return IQueryFunction + * @return string * @since 13.0.0 * * @psalm-taint-sink sql $x */ - public function emptyString($x): IQueryFunction; + public function emptyString($x): string; /** * Creates a `$x <> ''` statement, because Oracle needs a different check * * @param string|ILiteral|IParameter|IQueryFunction $x The field in string format to be inspected by the comparison. - * @return IQueryFunction + * @return string * @since 13.0.0 * * @psalm-taint-sink sql $x */ - public function nonEmptyString($x): IQueryFunction; + public function nonEmptyString($x): string; /** diff --git a/lib/public/DB/QueryBuilder/IFunctionBuilder.php b/lib/public/DB/QueryBuilder/IFunctionBuilder.php index 811e8d06aaf..d4edc8ea9f8 100644 --- a/lib/public/DB/QueryBuilder/IFunctionBuilder.php +++ b/lib/public/DB/QueryBuilder/IFunctionBuilder.php @@ -188,16 +188,4 @@ interface IFunctionBuilder { * @since 18.0.0 */ public function least($x, $y): IQueryFunction; - - /** - * Takes the minimum of multiple values - * - * If you want to get the minimum value of all rows in a column, use `min` instead - * - * @param array<array{"when": string|ILiteral|IParameter|IQueryFunction, "then": string|ILiteral|IParameter|IQueryFunction}> $whens - * @param string|ILiteral|IParameter|IQueryFunction $else - * @return IQueryFunction - * @since 18.0.0 - */ - public function case(array $whens, $else): IQueryFunction; } diff --git a/lib/public/DB/QueryBuilder/IQueryBuilder.php b/lib/public/DB/QueryBuilder/IQueryBuilder.php index 446e9a00b4c..218b7d8cb2d 100644 --- a/lib/public/DB/QueryBuilder/IQueryBuilder.php +++ b/lib/public/DB/QueryBuilder/IQueryBuilder.php @@ -503,7 +503,7 @@ interface IQueryBuilder { * @param string $fromAlias The alias that points to a from clause. * @param string $join The table name to join. * @param string $alias The alias of the join table. - * @param string|IQueryFunction|ICompositeExpression|null $condition The condition for the join. + * @param string|ICompositeExpression|null $condition The condition for the join. * * @return $this This QueryBuilder instance. * @since 8.2.0 @@ -528,7 +528,7 @@ interface IQueryBuilder { * @param string $fromAlias The alias that points to a from clause. * @param string $join The table name to join. * @param string $alias The alias of the join table. - * @param string|IQueryFunction|ICompositeExpression|null $condition The condition for the join. + * @param string|ICompositeExpression|null $condition The condition for the join. * * @return $this This QueryBuilder instance. * @since 8.2.0 @@ -553,7 +553,7 @@ interface IQueryBuilder { * @param string $fromAlias The alias that points to a from clause. * @param string $join The table name to join. * @param string $alias The alias of the join table. - * @param string|IQueryFunction|ICompositeExpression|null $condition The condition for the join. + * @param string|ICompositeExpression|null $condition The condition for the join. * * @return $this This QueryBuilder instance. * @since 8.2.0 @@ -578,7 +578,7 @@ interface IQueryBuilder { * @param string $fromAlias The alias that points to a from clause. * @param string $join The table name to join. * @param string $alias The alias of the join table. - * @param string|IQueryFunction|ICompositeExpression|null $condition The condition for the join. + * @param string|ICompositeExpression|null $condition The condition for the join. * * @return $this This QueryBuilder instance. * @since 8.2.0 |