diff options
author | Robin Appelman <robin@icewind.nl> | 2024-07-19 09:49:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-19 09:49:45 +0200 |
commit | 64ca4b832dc6b7a574fd3301b1c0e022b192ea5d (patch) | |
tree | f59cbd3a5440e1fb94e31fb06b25726a133f1193 /lib | |
parent | 0bde47a39256dfad3baa8d3ffa275ac3d113a9d5 (diff) | |
parent | c5b687271b59af5a2600f34e10b0e0907c159ab0 (diff) | |
download | nextcloud-server-64ca4b832dc6b7a574fd3301b1c0e022b192ea5d.tar.gz nextcloud-server-64ca4b832dc6b7a574fd3301b1c0e022b192ea5d.zip |
Merge pull request #46583 from nextcloud/filecache-sharding-compat
Make filecache queries compatible with sharding
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Cache/Cache.php | 9 | ||||
-rw-r--r-- | lib/private/Files/Cache/Propagator.php | 8 | ||||
-rw-r--r-- | lib/private/Files/Cache/QuerySearchHelper.php | 1 | ||||
-rw-r--r-- | lib/private/Files/Config/UserMountCache.php | 10 |
4 files changed, 16 insertions, 12 deletions
diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index c132ac1f034..a4290549dd9 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -120,11 +120,11 @@ class Cache implements ICache { // normalize file $file = $this->normalize($file); - $query->whereStorageId($this->getNumericStorageId()) - ->wherePath($file); + $query->wherePath($file); } else { //file id $query->whereFileId($file); } + $query->whereStorageId($this->getNumericStorageId()); $result = $query->execute(); $data = $result->fetch(); @@ -199,6 +199,7 @@ class Cache implements ICache { $query = $this->getQueryBuilder(); $query->selectFileCache() ->whereParent($fileId) + ->whereStorageId($this->getNumericStorageId()) ->orderBy('name', 'ASC'); $metadataQuery = $query->selectMetadata(); @@ -337,6 +338,7 @@ class Cache implements ICache { $query->update('filecache') ->whereFileId($id) + ->whereStorageId($this->getNumericStorageId()) ->andWhere($query->expr()->orX(...array_map(function ($key, $value) use ($query) { return $query->expr()->orX( $query->expr()->neq($key, $query->createNamedParameter($value)), @@ -512,6 +514,7 @@ class Cache implements ICache { if ($entry instanceof ICacheEntry) { $query = $this->getQueryBuilder(); $query->delete('filecache') + ->whereStorageId($this->getNumericStorageId()) ->whereFileId($entry->getId()); $query->execute(); @@ -583,6 +586,7 @@ class Cache implements ICache { $query = $this->getQueryBuilder(); $query->delete('filecache') + ->whereStorageId($this->getNumericStorageId()) ->whereParentInParameter('parentIds'); // Sorting before chunking allows the db to find the entries close to each @@ -929,6 +933,7 @@ class Cache implements ICache { $query = $this->getQueryBuilder(); $query->select('size', 'unencrypted_size') ->from('filecache') + ->whereStorageId($this->getNumericStorageId()) ->whereParent($id); if ($ignoreUnknown) { $query->andWhere($query->expr()->gte('size', $query->createNamedParameter(0))); diff --git a/lib/private/Files/Cache/Propagator.php b/lib/private/Files/Cache/Propagator.php index 5580dcf22a8..bbeb8c42075 100644 --- a/lib/private/Files/Cache/Propagator.php +++ b/lib/private/Files/Cache/Propagator.php @@ -186,15 +186,15 @@ class Propagator implements IPropagator { $query->update('filecache') ->set('mtime', $query->func()->greatest('mtime', $query->createParameter('time'))) ->set('etag', $query->expr()->literal(uniqid())) - ->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT))) + ->where($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) ->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash'))); $sizeQuery = $this->connection->getQueryBuilder(); $sizeQuery->update('filecache') ->set('size', $sizeQuery->func()->add('size', $sizeQuery->createParameter('size'))) - ->where($query->expr()->eq('storage', $query->expr()->literal($storageId, IQueryBuilder::PARAM_INT))) - ->andWhere($query->expr()->eq('path_hash', $query->createParameter('hash'))) - ->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->expr()->literal(-1, IQueryBuilder::PARAM_INT))); + ->where($query->expr()->eq('storage', $sizeQuery->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) + ->andWhere($query->expr()->eq('path_hash', $sizeQuery->createParameter('hash'))) + ->andWhere($sizeQuery->expr()->gt('size', $sizeQuery->createNamedParameter(-1, IQueryBuilder::PARAM_INT))); foreach ($this->batch as $item) { $query->setParameter('time', $item['time'], IQueryBuilder::PARAM_INT); diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index 5af43455ea3..0b164912301 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -110,7 +110,6 @@ class QuerySearchHelper { $query ->leftJoin('file', 'vcategory_to_object', 'tagmap', $query->expr()->eq('file.fileid', 'tagmap.objid')) ->leftJoin('tagmap', 'vcategory', 'tag', $query->expr()->andX( - $query->expr()->eq('tagmap.type', 'tag.type'), $query->expr()->eq('tagmap.categoryid', 'tag.id'), $query->expr()->eq('tag.type', $query->createNamedParameter('files')), $query->expr()->eq('tag.uid', $query->createNamedParameter($user->getUID())) diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index 0afdf9cdcc2..66aa3a6607b 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -237,7 +237,7 @@ class UserMountCache implements IUserMountCache { $builder = $this->connection->getQueryBuilder(); $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'mount_provider_class') ->from('mounts', 'm') - ->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($userUID))); + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userUID))); $result = $query->execute(); $rows = $result->fetchAll(); @@ -264,7 +264,7 @@ class UserMountCache implements IUserMountCache { $builder = $this->connection->getQueryBuilder(); $query = $builder->select('path') ->from('filecache') - ->where($builder->expr()->eq('fileid', $builder->createPositionalParameter($info->getRootId()))); + ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($info->getRootId()))); return $query->executeQuery()->fetchOne() ?: ''; } @@ -278,10 +278,10 @@ class UserMountCache implements IUserMountCache { $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', '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->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT))); + ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter($numericStorageId, IQueryBuilder::PARAM_INT))); if ($user) { - $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); + $query->andWhere($builder->expr()->eq('user_id', $builder->createNamedParameter($user))); } $result = $query->execute(); @@ -300,7 +300,7 @@ class UserMountCache implements IUserMountCache { $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', '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('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT))); + ->where($builder->expr()->eq('root_id', $builder->createNamedParameter($rootFileId, IQueryBuilder::PARAM_INT))); $result = $query->execute(); $rows = $result->fetchAll(); |