1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

[ticket/17062] Avoid calling search factory twice

PHPBB3-17062
This commit is contained in:
Ruben Calvo
2022-11-28 10:20:23 +01:00
parent 6fc476c692
commit b8bcbabaac

View File

@@ -15,6 +15,7 @@ namespace phpbb\cron\task\core;
use phpbb\config\config;
use phpbb\cron\task\base;
use phpbb\search\backend\search_backend_interface;
use phpbb\search\search_backend_factory;
/**
@@ -36,6 +37,12 @@ class tidy_search extends base
*/
protected $search_backend_factory;
/**
* Reference to active search backend to avoid calling the factory multiple times
* @var search_backend_interface
*/
protected $active_search;
/**
* Constructor.
*
@@ -55,8 +62,12 @@ class tidy_search extends base
*/
public function run()
{
$search = $this->search_backend_factory->get_active();
$search->tidy();
if ($this->active_search === null)
{
$this->active_search = $this->search_backend_factory->get_active();
}
$this->active_search->tidy();
}
/**
@@ -72,7 +83,10 @@ class tidy_search extends base
{
try
{
$this->search_backend_factory->get_active();
if ($this->active_search === null)
{
$this->active_search = $this->search_backend_factory->get_active();
}
}
catch (\RuntimeException $e)
{