fix cachjail searching for root
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
5d08beb3d2
commit
a20eb9a229
|
@ -166,6 +166,9 @@ class QuerySearchHelper {
|
||||||
$field = 'tag.category';
|
$field = 'tag.category';
|
||||||
} elseif ($field === 'fileid') {
|
} elseif ($field === 'fileid') {
|
||||||
$field = 'file.fileid';
|
$field = 'file.fileid';
|
||||||
|
} elseif ($field === 'path' && $type === ISearchComparison::COMPARE_EQUAL) {
|
||||||
|
$field = 'path_hash';
|
||||||
|
$value = md5((string)$value);
|
||||||
}
|
}
|
||||||
return [$field, $value, $type];
|
return [$field, $value, $type];
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,7 +238,10 @@ class CacheJail extends CacheWrapper {
|
||||||
$query = $this->getQueryBuilder();
|
$query = $this->getQueryBuilder();
|
||||||
$query->selectFileCache()
|
$query->selectFileCache()
|
||||||
->whereStorageId()
|
->whereStorageId()
|
||||||
->andWhere($query->expr()->like('path', $query->createNamedParameter($this->getRoot() . '/%')))
|
->andWhere($query->expr()->orX(
|
||||||
|
$query->expr()->like('path', $query->createNamedParameter($this->getRoot() . '/%')),
|
||||||
|
$query->expr()->eq('path_hash', $query->createNamedParameter(md5($this->getRoot()))),
|
||||||
|
))
|
||||||
->andWhere($query->expr()->iLike('name', $query->createNamedParameter($pattern)));
|
->andWhere($query->expr()->iLike('name', $query->createNamedParameter($pattern)));
|
||||||
|
|
||||||
$result = $query->execute();
|
$result = $query->execute();
|
||||||
|
@ -263,7 +266,10 @@ class CacheJail extends CacheWrapper {
|
||||||
$query = $this->getQueryBuilder();
|
$query = $this->getQueryBuilder();
|
||||||
$query->selectFileCache()
|
$query->selectFileCache()
|
||||||
->whereStorageId()
|
->whereStorageId()
|
||||||
->andWhere($query->expr()->like('path', $query->createNamedParameter($this->getRoot() . '/%')));
|
->andWhere($query->expr()->orX(
|
||||||
|
$query->expr()->like('path', $query->createNamedParameter($this->getRoot() . '/%')),
|
||||||
|
$query->expr()->eq('path_hash', $query->createNamedParameter(md5($this->getRoot()))),
|
||||||
|
));
|
||||||
|
|
||||||
if (strpos($mimetype, '/')) {
|
if (strpos($mimetype, '/')) {
|
||||||
$query->andWhere($query->expr()->eq('mimetype', $query->createNamedParameter($mimeId, IQueryBuilder::PARAM_INT)));
|
$query->andWhere($query->expr()->eq('mimetype', $query->createNamedParameter($mimeId, IQueryBuilder::PARAM_INT)));
|
||||||
|
@ -287,9 +293,14 @@ class CacheJail extends CacheWrapper {
|
||||||
'path',
|
'path',
|
||||||
$this->getRoot() . '/%'
|
$this->getRoot() . '/%'
|
||||||
);
|
);
|
||||||
|
$rootFilter = new SearchComparison(
|
||||||
|
ISearchComparison::COMPARE_EQUAL,
|
||||||
|
'path',
|
||||||
|
$this->getRoot()
|
||||||
|
);
|
||||||
$operation = new SearchBinaryOperator(
|
$operation = new SearchBinaryOperator(
|
||||||
ISearchBinaryOperator::OPERATOR_AND,
|
ISearchBinaryOperator::OPERATOR_AND,
|
||||||
[$prefixFilter, $query->getSearchOperation()]
|
[new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, [$prefixFilter, $rootFilter]) , $query->getSearchOperation()]
|
||||||
);
|
);
|
||||||
$simpleQuery = new SearchQuery($operation, 0, 0, $query->getOrder(), $query->getUser());
|
$simpleQuery = new SearchQuery($operation, 0, 0, $query->getOrder(), $query->getUser());
|
||||||
$results = $this->getCache()->searchQuery($simpleQuery);
|
$results = $this->getCache()->searchQuery($simpleQuery);
|
||||||
|
|
|
@ -37,6 +37,7 @@ class CacheJailTest extends CacheTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSearchOutsideJail() {
|
public function testSearchOutsideJail() {
|
||||||
|
$this->storage->getScanner()->scan('');
|
||||||
$file1 = 'foo/foobar';
|
$file1 = 'foo/foobar';
|
||||||
$file2 = 'folder/foobar';
|
$file2 = 'folder/foobar';
|
||||||
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
|
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
|
||||||
|
@ -49,9 +50,18 @@ class CacheJailTest extends CacheTest {
|
||||||
$result = $this->cache->search('%foobar%');
|
$result = $this->cache->search('%foobar%');
|
||||||
$this->assertCount(1, $result);
|
$this->assertCount(1, $result);
|
||||||
$this->assertEquals('foobar', $result[0]['path']);
|
$this->assertEquals('foobar', $result[0]['path']);
|
||||||
|
|
||||||
|
$result = $this->cache->search('%foo%');
|
||||||
|
$this->assertCount(2, $result);
|
||||||
|
usort($result, function ($a, $b) {
|
||||||
|
return $a['path'] <=> $b['path'];
|
||||||
|
});
|
||||||
|
$this->assertEquals('', $result[0]['path']);
|
||||||
|
$this->assertEquals('foobar', $result[1]['path']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSearchMimeOutsideJail() {
|
public function testSearchMimeOutsideJail() {
|
||||||
|
$this->storage->getScanner()->scan('');
|
||||||
$file1 = 'foo/foobar';
|
$file1 = 'foo/foobar';
|
||||||
$file2 = 'folder/foobar';
|
$file2 = 'folder/foobar';
|
||||||
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
|
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
|
||||||
|
@ -67,6 +77,7 @@ class CacheJailTest extends CacheTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSearchQueryOutsideJail() {
|
public function testSearchQueryOutsideJail() {
|
||||||
|
$this->storage->getScanner()->scan('');
|
||||||
$file1 = 'foo/foobar';
|
$file1 = 'foo/foobar';
|
||||||
$file2 = 'folder/foobar';
|
$file2 = 'folder/foobar';
|
||||||
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
|
$data1 = ['size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder'];
|
||||||
|
@ -76,11 +87,15 @@ class CacheJailTest extends CacheTest {
|
||||||
|
|
||||||
$user = new User('foo', null, $this->createMock(EventDispatcherInterface::class));
|
$user = new User('foo', null, $this->createMock(EventDispatcherInterface::class));
|
||||||
$query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foobar'), 10, 0, [], $user);
|
$query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foobar'), 10, 0, [], $user);
|
||||||
$this->assertCount(2, $this->sourceCache->searchQuery($query));
|
$result = $this->cache->searchQuery($query);
|
||||||
|
|
||||||
$result = $this->cache->search('%foobar%');
|
|
||||||
$this->assertCount(1, $result);
|
$this->assertCount(1, $result);
|
||||||
$this->assertEquals('foobar', $result[0]['path']);
|
$this->assertEquals('foobar', $result[0]['path']);
|
||||||
|
|
||||||
|
$query = new SearchQuery(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foo'), 10, 0, [], $user);
|
||||||
|
$result = $this->cache->searchQuery($query);
|
||||||
|
$this->assertCount(1, $result);
|
||||||
|
$this->assertEquals('', $result[0]['path']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testClearKeepEntriesOutsideJail() {
|
public function testClearKeepEntriesOutsideJail() {
|
||||||
|
|
Loading…
Reference in New Issue