Skip to content
Merged
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
fix: make migration for storing gf root and storage id compatible wit…
…h sharding

Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Jul 9, 2025
commit e67b6f2146d41570cc690ce99fabafd80665c043
27 changes: 17 additions & 10 deletions lib/Migration/Version20000Date20250612140256.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt

#[Override]
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
$rootIds = $this->getJailedRootIds();
$storageId = $this->getJailedGroupFolderStorageId();
if (count($rootIds) === 0 || $storageId === null) {
if ($storageId === null) {
return;
}
$rootIds = $this->getJailedRootIds($storageId);
if (count($rootIds) === 0) {
return;
}

Expand All @@ -62,7 +65,8 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
$query->update('group_folders')
->set('root_id', $query->createParameter('root_id'))
->set('storage_id', $query->createNamedParameter($storageId))
->where($query->expr()->eq('folder_id', $query->createParameter('folder_id')));
->where($query->expr()->eq('folder_id', $query->createParameter('folder_id')))
->andWhere($query->expr()->isNull('storage_id'));

foreach ($rootIds as $folderId => $rootId) {
$query->setParameter('root_id', $rootId);
Expand All @@ -80,16 +84,17 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
/**
* @return array<int, int>
*/
private function getJailedRootIds(): array {
$parentFolderId = $this->getJailedGroupFolderRootId();
private function getJailedRootIds(int $storageId): array {
$parentFolderId = $this->getJailedGroupFolderRootId($storageId);
if ($parentFolderId === null) {
return [];
}

$query = $this->connection->getQueryBuilder();
$query->select('name', 'fileid')
->from('filecache')
->where($query->expr()->eq('parent', $query->createNamedParameter($parentFolderId)));
->where($query->expr()->eq('parent', $query->createNamedParameter($parentFolderId)))
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId)));
$result = $query->executeQuery();

$rootIds = [];
Expand All @@ -101,14 +106,15 @@ private function getJailedRootIds(): array {
return $rootIds;
}

private function getJailedGroupFolderRootId(): ?int {
private function getJailedGroupFolderRootId(int $storageId): ?int {
$query = $this->connection->getQueryBuilder();
$query->select('fileid')
->from('filecache')
->andWhere($query->expr()->eq('path_hash', $query->createNamedParameter(md5('__groupfolders'))));
->where($query->expr()->eq('path_hash', $query->createNamedParameter(md5('__groupfolders'))))
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId)));

$id = $query->executeQuery()->fetchOne();
if ($id === null) {
if ($id === false) {
return null;
} else {
return (int)$id;
Expand All @@ -119,10 +125,11 @@ private function getJailedGroupFolderStorageId(): ?int {
$query = $this->connection->getQueryBuilder();
$query->select('storage')
->from('filecache')
->runAcrossAllShards()
->andWhere($query->expr()->eq('path_hash', $query->createNamedParameter(md5('__groupfolders'))));

$id = $query->executeQuery()->fetchOne();
if ($id === null) {
if ($id === false) {
return null;
} else {
return (int)$id;
Expand Down
Loading