Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,6 @@ public function __construct() {
'mounts_class_index',
['mount_provider_class']
);
$event->addMissingIndex(
'mounts',
'mounts_user_root_path_index',
['user_id', 'root_id', 'mount_point'],
['lengths' => [null, null, 128]]
);

$event->addMissingIndex(
'systemtag_object_mapping',
Expand Down
49 changes: 49 additions & 0 deletions core/Migrations/Version33000Date20251209123503.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC\Core\Migrations;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
use Override;

class Version33000Date20251209123503 extends SimpleMigrationStep {
public function __construct(
private readonly IDBConnection $connection,
) {
}

#[Override]
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
$this->connection->truncateTable('mounts', false);
}

#[Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$table = $schema->getTable('mounts');
if (!$table->hasColumn('mount_point_hash')) {
$table->addColumn('mount_point_hash', Types::STRING, [
'notnull' => true,
'length' => 32, // xxh128
]);
$table->dropIndex('mounts_user_root_path_index');
$table->addUniqueIndex(['user_id', 'root_id', 'mount_point_hash'], 'mounts_user_root_path_index');
return $schema;
}

return null;
}
}
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,7 @@
'OC\\Core\\Migrations\\Version31000Date20250213102442' => $baseDir . '/core/Migrations/Version31000Date20250213102442.php',
'OC\\Core\\Migrations\\Version31000Date20250731062008' => $baseDir . '/core/Migrations/Version31000Date20250731062008.php',
'OC\\Core\\Migrations\\Version32000Date20250620081925' => $baseDir . '/core/Migrations/Version32000Date20250620081925.php',
'OC\\Core\\Migrations\\Version33000Date20251209123503' => $baseDir . '/core/Migrations/Version33000Date20251209123503.php',
'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php',
'OC\\Core\\ResponseDefinitions' => $baseDir . '/core/ResponseDefinitions.php',
'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php',
Expand Down
9 changes: 5 additions & 4 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\' => 3,
'OCP\\' => 4,
),
'N' =>
'N' =>
array (
'NCU\\' => 4,
),
'B' =>
'B' =>
array (
'Bamarni\\Composer\\Bin\\' => 21,
),
Expand All @@ -40,11 +40,11 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
array (
0 => __DIR__ . '/../../..' . '/lib/public',
),
'NCU\\' =>
'NCU\\' =>
array (
0 => __DIR__ . '/../../..' . '/lib/unstable',
),
'Bamarni\\Composer\\Bin\\' =>
'Bamarni\\Composer\\Bin\\' =>
array (
0 => __DIR__ . '/..' . '/bamarni/composer-bin-plugin/src',
),
Expand Down Expand Up @@ -1520,6 +1520,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Core\\Migrations\\Version31000Date20250213102442' => __DIR__ . '/../../..' . '/core/Migrations/Version31000Date20250213102442.php',
'OC\\Core\\Migrations\\Version31000Date20250731062008' => __DIR__ . '/../../..' . '/core/Migrations/Version31000Date20250731062008.php',
'OC\\Core\\Migrations\\Version32000Date20250620081925' => __DIR__ . '/../../..' . '/core/Migrations/Version32000Date20250620081925.php',
'OC\\Core\\Migrations\\Version33000Date20251209123503' => __DIR__ . '/../../..' . '/core/Migrations/Version33000Date20251209123503.php',
'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php',
'OC\\Core\\ResponseDefinitions' => __DIR__ . '/../../..' . '/core/ResponseDefinitions.php',
'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php',
Expand Down
13 changes: 13 additions & 0 deletions lib/private/DB/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,19 @@ public function dropTable($table) {
}
}

/**
* Truncate a table data if it exists
*
* @param string $table table name without the prefix
* @param bool $cascade whether to truncate cascading
*
* @throws Exception
*/
public function truncateTable(string $table, bool $cascade) {
$this->executeStatement($this->getDatabasePlatform()
->getTruncateTableSQL($this->tablePrefix . trim($table), $cascade));
}

/**
* Check if a table exists
*
Expand Down
8 changes: 8 additions & 0 deletions lib/private/DB/ConnectionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ public function dropTable(string $table): void {
}
}

public function truncateTable(string $table, bool $cascade): void {
try {
$this->inner->truncateTable($table, $cascade);
} catch (Exception $e) {
throw DbalException::wrap($e);
}
}

public function tableExists(string $table): bool {
try {
return $this->inner->tableExists($table);
Expand Down
45 changes: 25 additions & 20 deletions lib/private/Files/Config/UserMountCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use OC\User\LazyUser;
use OCP\Cache\CappedMemoryCache;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
Expand Down Expand Up @@ -160,14 +161,25 @@ private function findChangedMounts(array $newMounts, array $cachedMounts): array

private function addToCache(ICachedMountInfo $mount) {
if ($mount->getStorageId() !== -1) {
$this->connection->insertIfNotExist('*PREFIX*mounts', [
'storage_id' => $mount->getStorageId(),
'root_id' => $mount->getRootId(),
'user_id' => $mount->getUser()->getUID(),
'mount_point' => $mount->getMountPoint(),
'mount_id' => $mount->getMountId(),
'mount_provider_class' => $mount->getMountProvider(),
], ['root_id', 'user_id', 'mount_point']);
$qb = $this->connection->getQueryBuilder();
$qb
->insert('mounts')
->values([
'storage_id' => $qb->createNamedParameter($mount->getStorageId(), IQueryBuilder::PARAM_INT),
'root_id' => $qb->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT),
'user_id' => $qb->createNamedParameter($mount->getUser()->getUID()),
'mount_point' => $qb->createNamedParameter($mount->getMountPoint()),
'mount_point_hash' => $qb->createNamedParameter(hash('xxh128', $mount->getMountPoint())),
'mount_id' => $qb->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT),
'mount_provider_class' => $qb->createNamedParameter($mount->getMountProvider()),
]);
try {
$qb->executeStatement();
} catch (Exception $e) {
if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
throw $e;
}
}
} else {
// in some cases this is legitimate, like orphaned shares
$this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint());
Expand All @@ -180,6 +192,7 @@ private function updateCachedMount(ICachedMountInfo $mount) {
$query = $builder->update('mounts')
->set('storage_id', $builder->createNamedParameter($mount->getStorageId()))
->set('mount_point', $builder->createNamedParameter($mount->getMountPoint()))
->set('mount_point_hash', $builder->createNamedParameter(hash('xxh128', $mount->getMountPoint())))
->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT))
->set('mount_provider_class', $builder->createNamedParameter($mount->getMountProvider()))
->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID())))
Expand All @@ -194,7 +207,7 @@ private function removeFromCache(ICachedMountInfo $mount) {
$query = $builder->delete('mounts')
->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID())))
->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT)))
->andWhere($builder->expr()->eq('mount_point', $builder->createNamedParameter($mount->getMountPoint())));
->andWhere($builder->expr()->eq('mount_point_hash', $builder->createNamedParameter(hash('xxh128', $mount->getMountPoint()))));
$query->executeStatement();
}

Expand Down Expand Up @@ -426,16 +439,8 @@ public function remoteStorageMounts($storageId) {
public function getUsedSpaceForUsers(array $users) {
$builder = $this->connection->getQueryBuilder();

$slash = $builder->createNamedParameter('/');

$mountPoint = $builder->func()->concat(
$builder->func()->concat($slash, 'user_id'),
$slash
);

$userIds = array_map(function (IUser $user) {
return $user->getUID();
}, $users);
$mountPointHashes = array_map(static fn (IUser $user) => hash('xxh128', '/' . $user->getUID() . '/'), $users);
$userIds = array_map(static fn (IUser $user) => $user->getUID(), $users);

$query = $builder->select('m.user_id', 'f.size')
->from('mounts', 'm')
Expand All @@ -444,7 +449,7 @@ public function getUsedSpaceForUsers(array $users) {
$builder->expr()->eq('m.storage_id', 'f.storage'),
$builder->expr()->eq('f.path_hash', $builder->createNamedParameter(md5('files')))
))
->where($builder->expr()->eq('m.mount_point', $mountPoint))
->where($builder->expr()->in('m.mount_point_hash', $builder->createNamedParameter($mountPointHashes, IQueryBuilder::PARAM_STR_ARRAY)))
->andWhere($builder->expr()->in('m.user_id', $builder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY)));

$result = $query->executeQuery();
Expand Down
15 changes: 15 additions & 0 deletions lib/public/IDBConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,21 @@ public function getDatabasePlatform();
*/
public function dropTable(string $table): void;

/**
* Truncate a table data if it exists
*
* Cascade is not supported on many platforms but would optionally cascade the truncate by
* following the foreign keys.
*
* @param string $table table name without the prefix
* @param bool $cascade whether to truncate cascading
* @throws Exception
* @since 31.0.13
*
* @psalm-taint-sink sql $table
*/
public function truncateTable(string $table, bool $cascade): void;

/**
* Check if a table exists
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private function setupFileCache(): void {
'storage_id' => $query->createNamedParameter(1001001, IQueryBuilder::PARAM_INT),
'user_id' => $query->createNamedParameter('partitioned_test'),
'mount_point' => $query->createNamedParameter('/mount/point'),
'mount_point_hash' => $query->createNamedParameter(hash('xxh128', '/mount/point')),
'mount_provider_class' => $query->createNamedParameter('test'),
'root_id' => $query->createNamedParameter($fileId, IQueryBuilder::PARAM_INT),
]);
Expand Down Expand Up @@ -134,7 +135,7 @@ public function testSimplePartitionedQuery(): void {
$builder->addPartition(new PartitionSplit('filecache', ['filecache']));

// query borrowed from UserMountCache
$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_point_hash', 'mount_id', 'f.path', 'mount_provider_class')
->from('mounts', 'm')
->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
->where($builder->expr()->eq('storage_id', $builder->createNamedParameter(1001001, IQueryBuilder::PARAM_INT)));
Expand All @@ -147,6 +148,7 @@ public function testSimplePartitionedQuery(): void {
$this->assertCount(1, $results);
$this->assertEquals($results[0]['user_id'], 'partitioned_test');
$this->assertEquals($results[0]['mount_point'], '/mount/point');
$this->assertEquals($results[0]['mount_point_hash'], hash('xxh128', '/mount/point'));
$this->assertEquals($results[0]['mount_provider_class'], 'test');
$this->assertEquals($results[0]['path'], 'file1');
}
Expand All @@ -155,7 +157,7 @@ public function testMultiTablePartitionedQuery(): void {
$builder = $this->getQueryBuilder();
$builder->addPartition(new PartitionSplit('filecache', ['filecache', 'filecache_extended']));

$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class', 'fe.upload_time')
$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_point_hash', 'mount_id', 'f.path', 'mount_provider_class', 'fe.upload_time')
->from('mounts', 'm')
->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
->innerJoin('f', 'filecache_extended', 'fe', $builder->expr()->eq('f.fileid', 'fe.fileid'))
Expand All @@ -169,6 +171,7 @@ public function testMultiTablePartitionedQuery(): void {
$this->assertCount(1, $results);
$this->assertEquals($results[0]['user_id'], 'partitioned_test');
$this->assertEquals($results[0]['mount_point'], '/mount/point');
$this->assertEquals($results[0]['mount_point_hash'], hash('xxh128', '/mount/point'));
$this->assertEquals($results[0]['mount_provider_class'], 'test');
$this->assertEquals($results[0]['path'], 'file1');
$this->assertEquals($results[0]['upload_time'], 1234);
Expand All @@ -178,7 +181,7 @@ public function testPartitionedQueryFromSplit(): void {
$builder = $this->getQueryBuilder();
$builder->addPartition(new PartitionSplit('filecache', ['filecache']));

$query = $builder->select('storage', 'm.root_id', 'm.user_id', 'm.mount_point', 'm.mount_id', 'path', 'm.mount_provider_class')
$query = $builder->select('storage', 'm.root_id', 'm.user_id', 'm.mount_point', 'm.mount_point_hash', 'm.mount_id', 'path', 'm.mount_provider_class')
->from('filecache', 'f')
->innerJoin('f', 'mounts', 'm', $builder->expr()->eq('m.root_id', 'f.fileid'));
$query->where($builder->expr()->eq('storage', $builder->createNamedParameter(1001001, IQueryBuilder::PARAM_INT)));
Expand All @@ -191,6 +194,7 @@ public function testPartitionedQueryFromSplit(): void {
$this->assertCount(1, $results);
$this->assertEquals($results[0]['user_id'], 'partitioned_test');
$this->assertEquals($results[0]['mount_point'], '/mount/point');
$this->assertEquals($results[0]['mount_point_hash'], hash('xxh128', '/mount/point'));
$this->assertEquals($results[0]['mount_provider_class'], 'test');
$this->assertEquals($results[0]['path'], 'file1');
}
Expand All @@ -200,7 +204,7 @@ public function testMultiJoinPartitionedQuery(): void {
$builder->addPartition(new PartitionSplit('filecache', ['filecache']));

// query borrowed from UserMountCache
$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_point_hash', 'mount_id', 'f.path', 'mount_provider_class')
->selectAlias('s.id', 'storage_string_id')
->from('mounts', 'm')
->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
Expand All @@ -215,6 +219,7 @@ public function testMultiJoinPartitionedQuery(): void {
$this->assertCount(1, $results);
$this->assertEquals($results[0]['user_id'], 'partitioned_test');
$this->assertEquals($results[0]['mount_point'], '/mount/point');
$this->assertEquals($results[0]['mount_point_hash'], hash('xxh128', '/mount/point'));
$this->assertEquals($results[0]['mount_provider_class'], 'test');
$this->assertEquals($results[0]['path'], 'file1');
$this->assertEquals($results[0]['storage_string_id'], 'test1');
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patch level
// when updating major/minor version number.

$OC_Version = [31, 0, 12, 3];
$OC_Version = [31, 0, 12, 4];

// The human-readable string
$OC_VersionString = '31.0.12';
Expand Down
Loading