aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2024-07-19 09:49:45 +0200
committerGitHub <noreply@github.com>2024-07-19 09:49:45 +0200
commit64ca4b832dc6b7a574fd3301b1c0e022b192ea5d (patch)
treef59cbd3a5440e1fb94e31fb06b25726a133f1193 /tests
parent0bde47a39256dfad3baa8d3ffa275ac3d113a9d5 (diff)
parentc5b687271b59af5a2600f34e10b0e0907c159ab0 (diff)
downloadnextcloud-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 'tests')
-rw-r--r--tests/lib/Files/Cache/PropagatorTest.php2
-rw-r--r--tests/lib/Files/Config/UserMountCacheTest.php55
2 files changed, 34 insertions, 23 deletions
diff --git a/tests/lib/Files/Cache/PropagatorTest.php b/tests/lib/Files/Cache/PropagatorTest.php
index 8902034db02..c0374f22233 100644
--- a/tests/lib/Files/Cache/PropagatorTest.php
+++ b/tests/lib/Files/Cache/PropagatorTest.php
@@ -122,7 +122,7 @@ class PropagatorTest extends TestCase {
foreach ($oldInfos as $i => $oldInfo) {
if ($oldInfo->getPath() !== 'foo/baz') {
- $this->assertNotEquals($oldInfo->getEtag(), $newInfos[$i]->getEtag());
+ $this->assertNotEquals($oldInfo->getEtag(), $newInfos[$i]->getEtag(), "etag for {$oldInfo->getPath()} not updated");
}
}
diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php
index 13690096d3a..d84f4469e8b 100644
--- a/tests/lib/Files/Config/UserMountCacheTest.php
+++ b/tests/lib/Files/Config/UserMountCacheTest.php
@@ -7,11 +7,13 @@
namespace Test\Files\Config;
+use OC\DB\Exceptions\DbalException;
use OC\DB\QueryBuilder\Literal;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Storage;
use OC\User\Manager;
use OCP\Cache\CappedMemoryCache;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\ICachedMountInfo;
@@ -335,29 +337,38 @@ class UserMountCacheTest extends TestCase {
private function createCacheEntry($internalPath, $storageId, $size = 0) {
$internalPath = trim($internalPath, '/');
- $inserted = $this->connection->insertIfNotExist('*PREFIX*filecache', [
- 'storage' => $storageId,
- 'path' => $internalPath,
- 'path_hash' => md5($internalPath),
- 'parent' => -1,
- 'name' => basename($internalPath),
- 'mimetype' => 0,
- 'mimepart' => 0,
- 'size' => $size,
- 'storage_mtime' => 0,
- 'encrypted' => 0,
- 'unencrypted_size' => 0,
- 'etag' => '',
- 'permissions' => 31
- ], ['storage', 'path_hash']);
- if ($inserted) {
- $id = (int)$this->connection->lastInsertId('*PREFIX*filecache');
+ try {
+ $query = $this->connection->getQueryBuilder();
+ $query->insert('filecache')
+ ->values([
+ 'storage' => $query->createNamedParameter($storageId),
+ 'path' => $query->createNamedParameter($internalPath),
+ 'path_hash' => $query->createNamedParameter(md5($internalPath)),
+ 'parent' => $query->createNamedParameter(-1, IQueryBuilder::PARAM_INT),
+ 'name' => $query->createNamedParameter(basename($internalPath)),
+ 'mimetype' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
+ 'mimepart' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
+ 'size' => $query->createNamedParameter($size),
+ 'storage_mtime' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
+ 'encrypted' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
+ 'unencrypted_size' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
+ 'etag' => $query->createNamedParameter(''),
+ 'permissions' => $query->createNamedParameter(31, IQueryBuilder::PARAM_INT),
+ ]);
+ $query->executeStatement();
+ $id = $query->getLastInsertId();
$this->fileIds[] = $id;
- } else {
- $sql = 'SELECT `fileid` FROM `*PREFIX*filecache` WHERE `storage` = ? AND `path_hash` =?';
- $query = $this->connection->prepare($sql);
- $query->execute([$storageId, md5($internalPath)]);
- return (int)$query->fetchOne();
+ } catch (DbalException $e) {
+ if ($e->getReason() === DbalException::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
+ $query = $this->connection->getQueryBuilder();
+ $query->select('fileid')
+ ->from('filecache')
+ ->where($query->expr()->eq('storage', $query->createNamedParameter($storageId)))
+ ->andWhere($query->expr()->eq('path_hash', $query->createNamedParameter(md5($internalPath))));
+ $id = (int)$query->execute()->fetchColumn();
+ } else {
+ throw $e;
+ }
}
return $id;
}