diff --git a/Classes/Domain/Search/CachedSearchService.php b/Classes/Domain/Search/CachedSearchService.php deleted file mode 100644 index a8655f3..0000000 --- a/Classes/Domain/Search/CachedSearchService.php +++ /dev/null @@ -1,69 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -use Codappix\SearchCore\Connection\SearchRequestInterface; -use Codappix\SearchCore\Connection\SearchResultInterface; -use TYPO3\CMS\Core\SingletonInterface; - -/** - * Service to process a search request, only once per request. - */ -class CachedSearchService implements SingletonInterface, SearchServiceInterface -{ - /** - * @var array - */ - protected $results = []; - - /** - * @var SearchService - */ - protected $searchService; - - public function __construct(SearchService $searchService) - { - $this->searchService = $searchService; - } - - public function search(SearchRequestInterface $searchRequest): SearchResultInterface - { - $hash = $this->getHash($searchRequest); - if (isset($this->results[$hash]) && $this->results[$hash] instanceof SearchResultInterface) { - return $this->results[$hash]; - } - return $this->results[$hash] = $this->searchService->search($searchRequest); - } - - public function processResult(SearchResultInterface $searchResult): SearchResultInterface - { - return $this->searchService->processResult($searchResult); - } - - protected function getHash(SearchRequestInterface $searchRequest): string - { - if (is_callable([$searchRequest, 'getRequestHash'])) { - return (string)$searchRequest->getRequestHash(); - } - return sha1(serialize($searchRequest)); - } -} diff --git a/Documentation/source/changelog/0.1.0/2018-changed-interfaces.rst b/Documentation/source/changelog/0.1.0/2018-changed-interfaces.rst index 93d5c81..740acb3 100644 --- a/Documentation/source/changelog/0.1.0/2018-changed-interfaces.rst +++ b/Documentation/source/changelog/0.1.0/2018-changed-interfaces.rst @@ -25,8 +25,8 @@ Some interfaces and abstract classes have been adjusted: Also some exceptions have changed: * ``Codappix\SearchCore\Connection\Elasticsearch\DocumentFactory::getDocument()`` now -throws an ``\InvalidArgumentException`` instead of ``\Exception``, if no -``search_identifier`` was provided. + throws an ``\InvalidArgumentException`` instead of ``\Exception``, if no + ``search_identifier`` was provided. * ``Codappix\SearchCore\Connection\Elasticsearch\IndexFactory::getIndex()`` now throws an ``\InvalidArgumentException`` if the index does not exist. Leaving diff --git a/Tests/Unit/Controller/SearchControllerTest.php b/Tests/Unit/Controller/SearchControllerTest.php index 0357b86..6c9fed6 100644 --- a/Tests/Unit/Controller/SearchControllerTest.php +++ b/Tests/Unit/Controller/SearchControllerTest.php @@ -23,7 +23,7 @@ namespace Codappix\Tests\Unit\Controller; use Codappix\SearchCore\Controller\SearchController; use Codappix\SearchCore\Domain\Model\SearchRequest; -use Codappix\SearchCore\Domain\Search\CachedSearchService; +use Codappix\SearchCore\Domain\Search\SearchService; use Codappix\SearchCore\Tests\Unit\AbstractUnitTestCase; use TYPO3\CMS\Extbase\Mvc\Web\Request; use TYPO3\CMS\Extbase\Object\ObjectManager; @@ -55,7 +55,7 @@ class SearchControllerTest extends AbstractUnitTestCase parent::setUp(); - $searchService = $this->getMockBuilder(CachedSearchService::class) + $searchService = $this->getMockBuilder(SearchService::class) ->disableOriginalConstructor() ->getMock(); $this->request = new Request(); diff --git a/ext_localconf.php b/ext_localconf.php index 0941be3..f400aa5 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -58,14 +58,12 @@ (isset($configuration['disable.']['elasticsearch']) && filter_var($configuration['disable.']['elasticsearch'], FILTER_VALIDATE_BOOLEAN) === false) ) { - $container = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class); + $container = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( + \TYPO3\CMS\Extbase\Object\Container\Container::class + ); $container->registerImplementation( \Codappix\SearchCore\Connection\ConnectionInterface::class, \Codappix\SearchCore\Connection\Elasticsearch::class ); - $container->registerImplementation( - \Codappix\SearchCore\Domain\Search\SearchServiceInterface::class, - \Codappix\SearchCore\Domain\Search\CachedSearchService::class - ); } })($_EXTKEY, $_EXTCONF);