Skip to content

Conversation

@icewind1991
Copy link
Member

@icewind1991 icewind1991 commented Feb 14, 2024

  • block queries to filecache tables that don't go through the sharding logic
  • allow getting a query builder for the filecache tables when provided a storage id to select a shard
    • probably not going to expose this to apps and leave it internal for the cache handling
  • provide methods for querying by fileid without known storage

github-advanced-security[bot]

This comment was marked as resolved.

@skjnldsv skjnldsv added the 2. developing Work in progress label Feb 21, 2024
* @return $this This QueryBuilder instance.
*/
public function from($from, $alias = null) {
$this->checkTableAccess($from);

Check failure

Code scanning / Psalm

ImplicitToStringCast

Argument 1 of OC\DB\QueryBuilder\QueryBuilder::checkTableAccess expects string, but OCP\DB\QueryBuilder\IQueryFunction|string provided with a __toString method
}

/**
* @param List<int> $storages

Check failure

Code scanning / Psalm

UndefinedDocblockClass

Docblock-defined class, interface or enum named OC\Files\Cache\List does not exist
}

/**
* @param List<int> $storages

Check failure

Code scanning / Psalm

MismatchingDocblockParamType

Parameter $storages has wrong type 'OC\Files\Cache\List<int>', should be 'array<array-key, mixed>'

/**
* @param List<int> $storages
* @return array<int, List<int>>

Check failure

Code scanning / Psalm

UndefinedDocblockClass

Docblock-defined class, interface or enum named OC\Files\Cache\List does not exist
* The results from the callback will be combined and returned
*
* @template T
* @param List<int> $storages

Check failure

Code scanning / Psalm

UndefinedDocblockClass

Docblock-defined class, interface or enum named OC\Files\Cache\List does not exist
if (in_array('owner', $requestedFields) || in_array('share_with', $requestedFields) || in_array('share_type', $requestedFields)) {
$this->equipQueryForShares($query);
}
$rawEntries = $this->cacheDatabase->queryStorages($storageIds, function(CacheQueryBuilder $builder, $storages) use ($requestedFields, $searchQuery, $cachesByStorage) {

Check failure

Code scanning / Psalm

InvalidArgument

Argument 1 of OC\Files\Cache\CacheDatabase::queryStorages expects OC\Files\Cache\List<int>, but array<T:fn-oc\files\cache\querysearchhelper::searchincaches as array-key, int> provided
$this->equipQueryForShares($query);
}
$rawEntries = $this->cacheDatabase->queryStorages($storageIds, function(CacheQueryBuilder $builder, $storages) use ($requestedFields, $searchQuery, $cachesByStorage) {
$cachesForShard = array_map(fn (int $storage) => $cachesByStorage[$storage], $storages);

Check failure

Code scanning / Psalm

InvalidArgument

Argument 2 of array_map expects array<array-key, mixed>, but OC\Files\Cache\List<int> provided
$result->closeCursor();

return $list;
return $this->cacheDatabase->queryStorages($storageIds, function(CacheQueryBuilder $qb, array $storages) use ($fileIdsByStorage) {

Check failure

Code scanning / Psalm

InvalidArgument

Argument 1 of OC\Files\Cache\CacheDatabase::queryStorages expects OC\Files\Cache\List<int>, but array<array-key, int|mixed> provided
Comment on lines 128 to 149
return $this->cacheDatabase->queryStorages($storageIds, function(CacheQueryBuilder $qb, array $storages) use ($fileIdsByStorage) {
$fileIds = [];
foreach ($storages as $storage) {
$fileIds += $fileIdsByStorage[$storage];
}

$qb->select('file_id', 'json', 'sync_token')->from(self::TABLE_METADATA);
$qb->where(
$qb->expr()->in('file_id', $qb->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))
);

$list = [];
$result = $qb->executeQuery();
while ($data = $result->fetch()) {
$fileId = (int) $data['file_id'];
$metadata = new FilesMetadata($fileId);
try {
$metadata->importFromDatabase($data);
} catch (FilesMetadataNotFoundException) {
continue;
}
$list[$fileId] = $metadata;
}
return $list;
});

Check failure

Code scanning / Psalm

InvalidArgument

Argument 2 of OC\Files\Cache\CacheDatabase::queryStorages expects callable(OC\Files\Cache\CacheQueryBuilder, OC\Files\Cache\List<int>):array<array-key, mixed>, but impure-Closure(OC\Files\Cache\CacheQueryBuilder, array<array-key, mixed>):array<int, OC\FilesMetadata\Model\FilesMetadata> provided
@icewind1991 icewind1991 force-pushed the filecache-chunking branch 7 times, most recently from f06b5b8 to 6d4e9c0 Compare March 6, 2024 13:54
*/
public function store(IFilesMetadata $filesMetadata): void {
$qb = $this->dbConnection->getQueryBuilder();
$file = $this->cacheDatabase->getByFileId($filesMetadata->getFileId());

Check failure

Code scanning / Psalm

UndefinedMethod

Method OC\Files\Cache\CacheDatabase::getByFileId does not exist
public function getMetadataFromFileId(int $fileId): IFilesMetadata {
try {
$qb = $this->dbConnection->getQueryBuilder();
$file = $this->cacheDatabase->getByFileId($fileId);

Check failure

Code scanning / Psalm

UndefinedMethod

Method OC\Files\Cache\CacheDatabase::getByFileId does not exist
$list[$fileId] = $metadata;
public function getMetadataFromFileIds(array $fileIds, array $storageIds = []): array {
if (!$storageIds) {
$files = $this->cacheDatabase->getByFileIds($fileIds);

Check failure

Code scanning / Psalm

UndefinedMethod

Method OC\Files\Cache\CacheDatabase::getByFileIds does not exist
$qb->delete(self::TABLE_METADATA)
->where($qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
$qb->executeStatement();
$file = $this->cacheDatabase->getByFileId($fileId);

Check failure

Code scanning / Psalm

UndefinedMethod

Method OC\Files\Cache\CacheDatabase::getByFileId does not exist
*/
public function updateMetadata(IFilesMetadata $filesMetadata): int {
$qb = $this->dbConnection->getQueryBuilder();
$file = $this->cacheDatabase->getByFileId($filesMetadata->getFileId());

Check failure

Code scanning / Psalm

UndefinedMethod

Method OC\Files\Cache\CacheDatabase::getByFileId does not exist
@icewind1991 icewind1991 force-pushed the filecache-chunking branch 2 times, most recently from 8aa41af to adc3d9c Compare May 22, 2024 15:11
Signed-off-by: Robin Appelman <[email protected]>
not as performant but compatible with sharding

Signed-off-by: Robin Appelman <[email protected]>
@icewind1991 icewind1991 force-pushed the filecache-chunking branch from adc3d9c to 4c6aabf Compare May 22, 2024 15:12
for ($i = 1; $i <= $retryLimit; $i++) {
try {
$this->connection->beginTransaction();
$this->cacheDb->beginTransaction();

Check failure

Code scanning / Psalm

TooFewArguments

Too few arguments for OC\Files\Cache\CacheDatabase::beginTransaction - expecting storageId to be passed
for ($i = 1; $i <= $retryLimit; $i++) {
try {
$this->connection->beginTransaction();
$this->cacheDb->beginTransaction();

Check failure

Code scanning / Psalm

TooFewArguments

Too few arguments for method OC\Files\Cache\CacheDatabase::begintransaction saw 0
}

$this->connection->rollBack();
$this->cacheDb->rollBack();

Check failure

Code scanning / Psalm

TooFewArguments

Too few arguments for OC\Files\Cache\CacheDatabase::rollBack - expecting storageId to be passed
}

$this->connection->rollBack();
$this->cacheDb->rollBack();

Check failure

Code scanning / Psalm

TooFewArguments

Too few arguments for method OC\Files\Cache\CacheDatabase::rollback saw 0
}
} else {
$this->connection->beginTransaction();
$this->cacheDb->beginTransaction();

Check failure

Code scanning / Psalm

TooFewArguments

Too few arguments for OC\Files\Cache\CacheDatabase::beginTransaction - expecting storageId to be passed
}
} else {
$this->connection->beginTransaction();
$this->cacheDb->beginTransaction();

Check failure

Code scanning / Psalm

TooFewArguments

Too few arguments for method OC\Files\Cache\CacheDatabase::begintransaction saw 0
foreach ($shares as $share) {
if (isset($files[$share->getNodeId()])) {
$cacheItem = $files[$share->getNodeId()];
if ($this->isAccessibleResult($cacheItem->getData())) {

Check failure

Code scanning / Psalm

UndefinedInterfaceMethod

Method OCP\Files\Cache\ICacheEntry::getData does not exist
@skjnldsv skjnldsv modified the milestones: Nextcloud 30, Nextcloud 31 Aug 14, 2024
@AndyScherzinger AndyScherzinger removed this from the Nextcloud 31 milestone Sep 4, 2024
@susnux susnux deleted the filecache-chunking branch November 1, 2025 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developing Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants