chore: Apply php:cs recommendations

Signed-off-by: Louis Chemineau <louis@chmn.me>
pull/46639/head
Louis Chemineau 2 years ago
parent 9d0248545d
commit 2574cbfa61
No known key found for this signature in database
  1. 4
      apps/files/lib/BackgroundJob/ScanFiles.php
  2. 2
      apps/files_sharing/lib/DeleteOrphanedSharesJob.php
  3. 4
      lib/private/DB/ArrayResult.php
  4. 8
      lib/private/DB/QueryBuilder/Partitioned/JoinCondition.php
  5. 4
      lib/private/DB/QueryBuilder/Partitioned/PartitionedQueryBuilder.php
  6. 20
      lib/private/DB/QueryBuilder/Sharded/AutoIncrementHandler.php
  7. 8
      lib/private/DB/QueryBuilder/Sharded/CrossShardMoveHelper.php
  8. 2
      lib/private/DB/QueryBuilder/Sharded/ShardDefinition.php
  9. 4
      lib/private/DB/QueryBuilder/Sharded/ShardQueryRunner.php
  10. 10
      lib/private/DB/QueryBuilder/Sharded/ShardedQueryBuilder.php
  11. 18
      lib/private/Files/Cache/Cache.php
  12. 2
      tests/lib/DB/QueryBuilder/Partitioned/JoinConditionTest.php
  13. 4
      tests/lib/DB/QueryBuilder/Sharded/SharedQueryBuilderTest.php
  14. 14
      tests/lib/Files/Cache/CacheTest.php
  15. 4
      tests/lib/Preview/BackgroundCleanupJobTest.php
  16. 12
      tests/preseed-config.php

@ -70,7 +70,7 @@ class ScanFiles extends TimedJob {
* @return string|false
*/
private function getUserToScan() {
if ($this->connection->getShardDefinition("filecache")) {
if ($this->connection->getShardDefinition('filecache')) {
// for sharded filecache, the "LIMIT" from the normal query doesn't work
// first we try it with a "LEFT JOIN" on mounts, this is fast, but might return a storage that isn't mounted.
@ -82,7 +82,7 @@ class ScanFiles extends TimedJob {
->where($query->expr()->lt('f.size', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->gt('f.parent', $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT)))
->setMaxResults(10)
->groupBy("f.storage")
->groupBy('f.storage')
->runAcrossAllShards();
$result = $query->executeQuery();

@ -120,7 +120,7 @@ class DeleteOrphanedSharesJob extends TimedJob {
$this->atomic(function () use ($deletedFiles, $deleteQb) {
$deleteQb->setParameter('ids', $deletedFiles, IQueryBuilder::PARAM_INT_ARRAY);
$deleted = $deleteQb->executeStatement();
$this->logger->debug("{deleted} orphaned share(s) deleted", [
$this->logger->debug('{deleted} orphaned share(s) deleted', [
'app' => 'DeleteOrphanedSharesJob',
'deleted' => $deleted,
]);

@ -37,7 +37,7 @@ class ArrayResult implements IResult {
PDO::FETCH_ASSOC => $row,
PDO::FETCH_NUM => array_values($row),
PDO::FETCH_COLUMN => current($row),
default => throw new \InvalidArgumentException("Fetch mode not supported for array result"),
default => throw new \InvalidArgumentException('Fetch mode not supported for array result'),
};
}
@ -51,7 +51,7 @@ class ArrayResult implements IResult {
PDO::FETCH_COLUMN => array_map(function ($row) {
return current($row);
}, $this->rows),
default => throw new \InvalidArgumentException("Fetch mode not supported for array result"),
default => throw new \InvalidArgumentException('Fetch mode not supported for array result'),
};
}

@ -37,8 +37,8 @@ class JoinCondition {
* @return JoinCondition
*/
public static function merge(array $conditions): JoinCondition {
$fromColumn = "";
$toColumn = "";
$fromColumn = '';
$toColumn = '';
$fromAlias = null;
$toAlias = null;
$fromConditions = [];
@ -99,9 +99,9 @@ class JoinCondition {
$isSubCondition = self::isExtraCondition($condition);
if ($isSubCondition) {
if (self::mentionsAlias($condition, $fromAlias)) {
return new JoinCondition("", null, "", null, [$condition], []);
return new JoinCondition('', null, '', null, [$condition], []);
} else {
return new JoinCondition("", null, "", null, [], [$condition]);
return new JoinCondition('', null, '', null, [], [$condition]);
}
}

@ -391,10 +391,10 @@ class PartitionedQueryBuilder extends ShardedQueryBuilder {
}, false);
if ($hasNonLeftJoins) {
if (is_int($this->limit)) {
throw new InvalidPartitionedQueryException("Limit is not allowed in partitioned queries");
throw new InvalidPartitionedQueryException('Limit is not allowed in partitioned queries');
}
if (is_int($this->offset)) {
throw new InvalidPartitionedQueryException("Offset is not allowed in partitioned queries");
throw new InvalidPartitionedQueryException('Offset is not allowed in partitioned queries');
}
}
}

@ -29,13 +29,13 @@ class AutoIncrementHandler {
private ShardConnectionManager $shardConnectionManager,
) {
if (PHP_INT_SIZE < 8) {
throw new \Exception("sharding is only supported with 64bit php");
throw new \Exception('sharding is only supported with 64bit php');
}
}
private function getCache(): IMemcache {
if(is_null($this->cache)) {
$cache = $this->cacheFactory->createDistributed("shared_autoincrement");
$cache = $this->cacheFactory->createDistributed('shared_autoincrement');
if ($cache instanceof IMemcache) {
$this->cache = $cache;
} else {
@ -61,7 +61,7 @@ class AutoIncrementHandler {
$next = $this->getNextInner($shardDefinition);
if ($next !== null) {
if ($next > ShardDefinition::MAX_PRIMARY_KEY) {
throw new \Exception("Max primary key of " . ShardDefinition::MAX_PRIMARY_KEY . " exceeded");
throw new \Exception('Max primary key of ' . ShardDefinition::MAX_PRIMARY_KEY . ' exceeded');
}
// we encode the shard the primary key was originally inserted into to allow guessing the shard by primary key later on
return ($next << 8) | $shard;
@ -69,7 +69,7 @@ class AutoIncrementHandler {
$retries++;
}
}
throw new \Exception("Failed to get next primary key");
throw new \Exception('Failed to get next primary key');
}
/**
@ -88,7 +88,7 @@ class AutoIncrementHandler {
// if that is not the case we find the highest used id in the database increment it, and save it in the cache
// prevent inc from returning `1` if the key doesn't exist by setting it to a non-numeric value
$cache->add($shardDefinition->table, "empty-placeholder", self::TTL);
$cache->add($shardDefinition->table, 'empty-placeholder', self::TTL);
$next = $cache->inc($shardDefinition->table);
if ($cache instanceof IMemcacheTTL) {
@ -101,7 +101,7 @@ class AutoIncrementHandler {
return $next;
} elseif (is_int($next)) {
// we hit the edge case, so invalidate the cached value
if (!$cache->cas($shardDefinition->table, $next, "empty-placeholder")) {
if (!$cache->cas($shardDefinition->table, $next, 'empty-placeholder')) {
// someone else is changing the value concurrently, give up and retry
return null;
}
@ -110,7 +110,7 @@ class AutoIncrementHandler {
// discard the encoded initial shard
$current = $this->getMaxFromDb($shardDefinition) >> 8;
$next = max($current, self::MIN_VALID_KEY) + 1;
if ($cache->cas($shardDefinition->table, "empty-placeholder", $next)) {
if ($cache->cas($shardDefinition->table, 'empty-placeholder', $next)) {
return $next;
}
@ -120,11 +120,11 @@ class AutoIncrementHandler {
return $next;
} elseif(is_int($next)) {
// key got cleared, invalidate and retry
$cache->cas($shardDefinition->table, $next, "empty-placeholder");
$cache->cas($shardDefinition->table, $next, 'empty-placeholder');
return null;
} else {
// cleanup any non-numeric value other than the placeholder if that got stored somehow
$cache->ncad($shardDefinition->table, "empty-placeholder");
$cache->ncad($shardDefinition->table, 'empty-placeholder');
// retry
return null;
}
@ -140,7 +140,7 @@ class AutoIncrementHandler {
$query = $connection->getQueryBuilder();
$query->select($shardDefinition->primaryKey)
->from($shardDefinition->table)
->orderBy($shardDefinition->primaryKey, "DESC")
->orderBy($shardDefinition->primaryKey, 'DESC')
->setMaxResults(1);
$result = $query->executeQuery()->fetchOne();
if ($result) {

@ -83,13 +83,13 @@ class CrossShardMoveHelper {
$query = $connection->getQueryBuilder();
$query->select('*')
->from($table)
->where($query->expr()->in($primaryColumn, $query->createParameter("keys")));
->where($query->expr()->in($primaryColumn, $query->createParameter('keys')));
$chunks = array_chunk($primaryKeys, 1000);
$results = [];
foreach ($chunks as $chunk) {
$query->setParameter("keys", $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$query->setParameter('keys', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$results = array_merge($results, $query->execute()->fetchAll());
}
@ -151,11 +151,11 @@ class CrossShardMoveHelper {
public function deleteItems(IDBConnection $connection, string $table, string $primaryColumn, array $primaryKeys): void {
$query = $connection->getQueryBuilder();
$query->delete($table)
->where($query->expr()->in($primaryColumn, $query->createParameter("keys")));
->where($query->expr()->in($primaryColumn, $query->createParameter('keys')));
$chunks = array_chunk($primaryKeys, 1000);
foreach ($chunks as $chunk) {
$query->setParameter("keys", $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$query->setParameter('keys', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$query->executeStatement();
}
}

@ -41,7 +41,7 @@ class ShardDefinition {
public array $shards = [],
) {
if (count($this->shards) >= self::MAX_SHARDS) {
throw new \Exception("Only allowed maximum of " . self::MAX_SHARDS . " shards allowed");
throw new \Exception('Only allowed maximum of ' . self::MAX_SHARDS . ' shards allowed');
}
}

@ -135,7 +135,7 @@ class ShardQueryRunner {
if ($cmp === 0) {
continue;
}
if ($sort['order'] === "DESC") {
if ($sort['order'] === 'DESC') {
$cmp = -$cmp;
}
return $cmp;
@ -166,7 +166,7 @@ class ShardQueryRunner {
*/
public function executeStatement(IQueryBuilder $query, bool $allShards, array $shardKeys, array $primaryKeys): int {
if ($query->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT) {
throw new \Exception("insert queries need special handling");
throw new \Exception('insert queries need special handling');
}
$shards = $this->getShards($allShards, $shardKeys);

@ -36,7 +36,7 @@ class ShardedQueryBuilder extends ExtendedQueryBuilder {
private ?int $updateShardKey = null;
private ?int $limit = null;
private ?int $offset = null;
/** @var array{column: string, order: string}[] */
/** @var array{column: string, order: string}[] */
private array $sortList = [];
private string $mainTable = '';
@ -276,13 +276,13 @@ class ShardedQueryBuilder extends ExtendedQueryBuilder {
}
public function addOrderBy($sort, $order = null) {
$this->registerOrder((string) $sort, (string)$order ?? "ASC");
$this->registerOrder((string)$sort, (string)$order ?? 'ASC');
return parent::orderBy($sort, $order);
}
public function orderBy($sort, $order = null) {
$this->sortList = [];
$this->registerOrder((string) $sort, (string)$order ?? "ASC");
$this->registerOrder((string)$sort, (string)$order ?? 'ASC');
return parent::orderBy($sort, $order);
}
@ -329,7 +329,7 @@ class ShardedQueryBuilder extends ExtendedQueryBuilder {
}
if ($this->shardDefinition && !$this->allShards) {
if (empty($this->getShardKeys()) && empty($this->getPrimaryKeys())) {
throw new InvalidShardedQueryException("No shard key or primary key set for query");
throw new InvalidShardedQueryException('No shard key or primary key set for query');
}
}
if ($this->shardDefinition && $this->updateShardKey) {
@ -347,7 +347,7 @@ class ShardedQueryBuilder extends ExtendedQueryBuilder {
}, $oldShardKeys)));
$newShard = $this->shardDefinition->getShardForKey((int)$newShardKey);
if ($oldShards === [$newShard]) {
throw new InvalidShardedQueryException("Update statement would move rows to a different shard");
throw new InvalidShardedQueryException('Update statement would move rows to a different shard');
}
}
}

@ -1220,9 +1220,9 @@ class Cache implements ICache {
$sourceConnection = $helper->getConnection($shardDefinition, $sourceCache->getNumericStorageId());
$targetConnection = $helper->getConnection($shardDefinition, $this->getNumericStorageId());
$cacheItems = $helper->loadItems($sourceConnection, "filecache", "fileid", $fileIds);
$extendedItems = $helper->loadItems($sourceConnection, "filecache_extended", "fileid", $fileIds);
$metadataItems = $helper->loadItems($sourceConnection, "files_metadata", "file_id", $fileIds);
$cacheItems = $helper->loadItems($sourceConnection, 'filecache', 'fileid', $fileIds);
$extendedItems = $helper->loadItems($sourceConnection, 'filecache_extended', 'fileid', $fileIds);
$metadataItems = $helper->loadItems($sourceConnection, 'files_metadata', 'file_id', $fileIds);
// when moving from an encrypted storage to a non-encrypted storage remove the `encrypted` mark
$removeEncryptedFlag = ($sourceCache instanceof Cache && $sourceCache->hasEncryptionWrapper()) && !$this->hasEncryptionWrapper();
@ -1246,9 +1246,9 @@ class Cache implements ICache {
$targetConnection->beginTransaction();
try {
$helper->saveItems($targetConnection, "filecache", $cacheItems);
$helper->saveItems($targetConnection, "filecache_extended", $extendedItems);
$helper->saveItems($targetConnection, "files_metadata", $metadataItems);
$helper->saveItems($targetConnection, 'filecache', $cacheItems);
$helper->saveItems($targetConnection, 'filecache_extended', $extendedItems);
$helper->saveItems($targetConnection, 'files_metadata', $metadataItems);
} catch (\Exception $e) {
$targetConnection->rollback();
throw $e;
@ -1257,9 +1257,9 @@ class Cache implements ICache {
$sourceConnection->beginTransaction();
try {
$helper->deleteItems($sourceConnection, "filecache", "fileid", $fileIds);
$helper->deleteItems($sourceConnection, "filecache_extended", "fileid", $fileIds);
$helper->deleteItems($sourceConnection, "files_metadata", "file_id", $fileIds);
$helper->deleteItems($sourceConnection, 'filecache', 'fileid', $fileIds);
$helper->deleteItems($sourceConnection, 'filecache_extended', 'fileid', $fileIds);
$helper->deleteItems($sourceConnection, 'files_metadata', 'file_id', $fileIds);
} catch (\Exception $e) {
$targetConnection->rollback();
$sourceConnection->rollBack();

@ -47,7 +47,7 @@ class JoinConditionTest extends TestCase {
public function testParseCondition(string $platform): void {
$query = $this->getBuilder($platform);
$param1 = $query->createNamedParameter('files');
$param2 = $query->createNamedParameter("test");
$param2 = $query->createNamedParameter('test');
$condition = $query->expr()->andX(
$query->expr()->eq('tagmap.categoryid', 'tag.id'),
$query->expr()->eq('tag.type', $param1),

@ -91,7 +91,7 @@ class SharedQueryBuilderTest extends TestCase {
$this->expectException(InvalidShardedQueryException::class);
$query->validate();
$this->fail("exception expected");
$this->fail('exception expected');
}
public function testValidateNonSharedTable() {
@ -114,7 +114,7 @@ class SharedQueryBuilderTest extends TestCase {
$query->expr()->eq('storage', $query->createNamedParameter(10, IQueryBuilder::PARAM_INT)),
$query->expr()->andX(
$query->expr()->eq('storage', $query->createNamedParameter(11, IQueryBuilder::PARAM_INT)),
$query->expr()->like('path', $query->createNamedParameter("foo/%"))
$query->expr()->like('path', $query->createNamedParameter('foo/%'))
)
)
));

@ -487,17 +487,17 @@ class CacheTest extends \Test\TestCase {
$data = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/bar'];
$folderData = ['size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'];
$this->cache2->put("folder", $folderData);
$this->cache2->put("folder/sub", $data);
$this->cache2->put('folder', $folderData);
$this->cache2->put('folder/sub', $data);
$this->cache->moveFromCache($this->cache2, "folder", "targetfolder");
$this->cache->moveFromCache($this->cache2, 'folder', 'targetfolder');
$this->assertFalse($this->cache2->inCache("folder"));
$this->assertFalse($this->cache2->inCache("folder/sub"));
$this->assertFalse($this->cache2->inCache('folder'));
$this->assertFalse($this->cache2->inCache('folder/sub'));
$this->assertTrue($this->cache->inCache("targetfolder"));
$this->assertTrue($this->cache->inCache("targetfolder/sub"));
$this->assertTrue($this->cache->inCache('targetfolder'));
$this->assertTrue($this->cache->inCache('targetfolder/sub'));
}
public function testGetIncomplete() {

@ -147,7 +147,7 @@ class BackgroundCleanupJobTest extends \Test\TestCase {
public function testCleanupAjax() {
if ($this->connection->getShardDefinition('filecache')) {
$this->markTestSkipped("ajax cron is not supported for sharded setups");
$this->markTestSkipped('ajax cron is not supported for sharded setups');
return;
}
$files = $this->setup11Previews();
@ -179,7 +179,7 @@ class BackgroundCleanupJobTest extends \Test\TestCase {
public function testOldPreviews() {
if ($this->connection->getShardDefinition('filecache')) {
$this->markTestSkipped("old previews are not supported for sharded setups");
$this->markTestSkipped('old previews are not supported for sharded setups');
return;
}
$appdata = \OC::$server->getAppDataDir('preview');

@ -81,19 +81,19 @@ if (getenv('OBJECT_STORE') === 's3') {
if (getenv('SHARDING') == '1') {
$CONFIG['dbsharding'] = [
"filecache" => [
"shards" => [
'filecache' => [
'shards' => [
[
"port" => 5001,
'port' => 5001,
],
[
"port" => 5002,
'port' => 5002,
],
[
"port" => 5003,
'port' => 5003,
],
[
"port" => 5004,
'port' => 5004,
],
]
]

Loading…
Cancel
Save