0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-02-12 12:09:14 +00:00
nextcloud_server/lib/private/Files/Search/QueryOptimizer/SplitLargeIn.php
Robin Appelman 63ffaab95e
fix types + autoloader
Signed-off-by: Robin Appelman <robin@icewind.nl>
2024-02-15 17:55:43 +01:00

32 lines
1 KiB
PHP

<?php
namespace OC\Files\Search\QueryOptimizer;
use OC\Files\Search\SearchBinaryOperator;
use OC\Files\Search\SearchComparison;
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
use OCP\Files\Search\ISearchOperator;
/**
* transform IN (1000+ element) into (IN (1000 elements) OR IN(...))
*/
class SplitLargeIn extends ReplacingOptimizerStep {
public function processOperator(ISearchOperator &$operator): bool {
if (
$operator instanceof ISearchComparison &&
$operator->getType() === ISearchComparison::COMPARE_IN &&
count($operator->getValue()) > 1000
) {
$chunks = array_chunk($operator->getValue(), 1000);
$chunkComparisons = array_map(function (array $values) use ($operator) {
return new SearchComparison(ISearchComparison::COMPARE_IN, $operator->getField(), $values);
}, $chunks);
$operator = new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR, $chunkComparisons);
return true;
}
parent::processOperator($operator);
return false;
}
}