Optimize searches to prevent slow DB queries

This commit is contained in:
DariusIII
2026-03-09 10:28:00 +01:00
parent 98a0c3e5f9
commit 70dc51861d
4 changed files with 129 additions and 23 deletions
+39
View File
@@ -6,6 +6,7 @@ use App\Services\Search\Drivers\ManticoreSearchDriver;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
class ManticoreSearchQueryTest extends TestCase
{
@@ -168,4 +169,42 @@ class ManticoreSearchQueryTest extends TestCase
'array with -1 values' => [['searchname' => '-1'], false],
];
}
#[Test]
public function it_passes_release_search_limit_to_search_indexes(): void
{
$driver = new class extends ManticoreSearchDriver
{
public int $capturedLimit = 0;
public function __construct() {}
public function searchIndexes(string $rt_index, ?string $searchString, array $column = [], array $searchArray = [], int $limit = 1000): array
{
$this->capturedLimit = $limit;
return ['id' => [101, 202]];
}
};
$result = $driver->searchReleases(['searchname' => 'harry potter'], 75);
$this->assertSame(75, $driver->capturedLimit);
$this->assertSame([101, 202], $result);
}
#[Test]
public function it_clamps_search_limit_to_configured_max_matches(): void
{
$reflection = new ReflectionClass(ManticoreSearchDriver::class);
$driver = $reflection->newInstanceWithoutConstructor();
$configProperty = $reflection->getProperty('config');
$configProperty->setValue($driver, ['max_matches' => 500]);
$method = $reflection->getMethod('normalizeSearchLimit');
$this->assertSame(500, $method->invoke($driver, 750));
$this->assertSame(1, $method->invoke($driver, 0));
}
}