Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hint table for columns for sharded queries #1630

Merged
merged 2 commits into from
Jan 15, 2025
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
34 changes: 19 additions & 15 deletions lib/Mount/CollectiveFolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OC\Files\Storage\Wrapper\Jail;
use OC\Files\Storage\Wrapper\PermissionsMask;
use OCA\Collectives\ACL\ACLStorageWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Folder;
use OCP\Files\InvalidPathException;
Expand All @@ -36,7 +37,7 @@ class CollectiveFolderManager {
private const SUFFIX = '.md';

private ?string $rootPath = null;
private ?int $rootFolderStorageId = null;
private ?int $rootFolderId = null;

public function __construct(
private IRootFolder $rootFolder,
Expand Down Expand Up @@ -149,19 +150,23 @@ private function getJailPath(int $folderId): string {
/**
* @throws NotFoundException
*/
private function getRootFolderStorageId(): int {
if ($this->rootFolderStorageId === null) {
private function getRootFolderId(): int {
if ($this->rootFolderId === null) {
$qb = $this->connection->getQueryBuilder();

$qb->select('fileid')
->from('filecache')
->where($qb->expr()->eq('storage', $qb->createNamedParameter($this->getRootFolder()->getStorage()->getCache()->getNumericStorageId())))
$qb->select('f.fileid')
->from('filecache', 'f')
->where($qb->expr()->eq('storage', $qb->createNamedParameter($this->getRootFolderStorageId())))
->andWhere($qb->expr()->eq('path_hash', $qb->createNamedParameter(md5($this->getRootPath()))));

$this->rootFolderStorageId = (int)$qb->execute()->fetchColumn();
$this->rootFolderId = (int)$qb->execute()->fetchColumn();
}

return $this->rootFolderStorageId;
return $this->rootFolderId;
}

private function getRootFolderStorageId(): int {
return $this->getRootFolder()->getStorage()->getCache()->getNumericStorageId();
}

/**
Expand Down Expand Up @@ -194,14 +199,13 @@ public function getLandingPagePath(string $path, string $lang): string {
public function getFolderFileCache(int $id, string $name): array {
$qb = $this->connection->getQueryBuilder();
$qb->select(
'co.id AS folder_id', 'fileid', 'storage', 'path', 'fc.name AS name',
'mimetype', 'mimepart', 'size', 'mtime', 'storage_mtime', 'etag', 'encrypted', 'parent', 'fc.permissions AS permissions')
'co.id AS folder_id', 'fc.fileid', 'fc.storage', 'fc.path', 'fc.name AS name',
'fc.mimetype', 'fc.mimepart', 'fc.size', 'fc.mtime', 'fc.storage_mtime', 'fc.etag', 'fc.encrypted', 'fc.parent', 'fc.permissions AS permissions')
->from('collectives', 'co')
->leftJoin('co', 'filecache', 'fc', $qb->expr()->andX(
// concat with empty string to work around missing cast to string
$qb->expr()->eq('fc.name', $qb->func()->concat('co.id', $qb->expr()->literal(''))),
$qb->expr()->eq('parent', $qb->createNamedParameter($this->getRootFolderStorageId()))))
->where($qb->expr()->eq('co.id', $qb->createNamedParameter($id)));
->leftJoin('co', 'filecache', 'fc', $qb->expr()->eq('fc.name', $qb->expr()->castColumn('co.id', IQueryBuilder::PARAM_STR)))
->where($qb->expr()->eq('co.id', $qb->createNamedParameter($id)))
->andWhere($qb->expr()->eq('fc.parent', $qb->createNamedParameter($this->getRootFolderId())))
->andWhere($qb->expr()->eq('fc.storage', $qb->createNamedParameter($this->getRootFolderStorageId(), IQueryBuilder::PARAM_INT)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cannot judge whether specifying the storage id is safe here. Could there be, for example, incoming shares?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always be the storage id of the mount point and in the case of collectives the storage id of the root folder as collective data is stored in app data.

$cache = $qb->execute()->fetch();
$cache['mount_point'] = $name;
return $cache;
Expand Down
Loading