1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-02 23:07:39 +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\config\config;
use phpbb\cron\task\base; use phpbb\cron\task\base;
use phpbb\search\backend\search_backend_interface;
use phpbb\search\search_backend_factory; use phpbb\search\search_backend_factory;
/** /**
@@ -36,6 +37,12 @@ class tidy_search extends base
*/ */
protected $search_backend_factory; protected $search_backend_factory;
/**
* Reference to active search backend to avoid calling the factory multiple times
* @var search_backend_interface
*/
protected $active_search;
/** /**
* Constructor. * Constructor.
* *
@@ -55,8 +62,12 @@ class tidy_search extends base
*/ */
public function run() public function run()
{ {
$search = $this->search_backend_factory->get_active(); if ($this->active_search === null)
$search->tidy(); {
$this->active_search = $this->search_backend_factory->get_active();
}
$this->active_search->tidy();
} }
/** /**
@@ -72,7 +83,10 @@ class tidy_search extends base
{ {
try try
{ {
$this->search_backend_factory->get_active(); if ($this->active_search === null)
{
$this->active_search = $this->search_backend_factory->get_active();
}
} }
catch (\RuntimeException $e) catch (\RuntimeException $e)
{ {