TASK: Remove cache implementation

As it does not use TYPO3 caching framework but custom feature.
This commit is contained in:
Daniel Siepmann 2018-12-30 14:45:16 +01:00
parent a6f7f31274
commit 4c99009ea0
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
4 changed files with 7 additions and 78 deletions

View file

@ -1,69 +0,0 @@
<?php
namespace Codappix\SearchCore\Domain\Search;
/*
* Copyright (C) 2018 Benjamin Serfhos <benjamin@serfhos.com>
*
* 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));
}
}

View file

@ -23,7 +23,7 @@ namespace Codappix\Tests\Unit\Controller;
use Codappix\SearchCore\Controller\SearchController; use Codappix\SearchCore\Controller\SearchController;
use Codappix\SearchCore\Domain\Model\SearchRequest; 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 Codappix\SearchCore\Tests\Unit\AbstractUnitTestCase;
use TYPO3\CMS\Extbase\Mvc\Web\Request; use TYPO3\CMS\Extbase\Mvc\Web\Request;
use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Object\ObjectManager;
@ -55,7 +55,7 @@ class SearchControllerTest extends AbstractUnitTestCase
parent::setUp(); parent::setUp();
$searchService = $this->getMockBuilder(CachedSearchService::class) $searchService = $this->getMockBuilder(SearchService::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->request = new Request(); $this->request = new Request();

View file

@ -58,14 +58,12 @@
(isset($configuration['disable.']['elasticsearch']) && (isset($configuration['disable.']['elasticsearch']) &&
filter_var($configuration['disable.']['elasticsearch'], FILTER_VALIDATE_BOOLEAN) === false) 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( $container->registerImplementation(
\Codappix\SearchCore\Connection\ConnectionInterface::class, \Codappix\SearchCore\Connection\ConnectionInterface::class,
\Codappix\SearchCore\Connection\Elasticsearch::class \Codappix\SearchCore\Connection\Elasticsearch::class
); );
$container->registerImplementation(
\Codappix\SearchCore\Domain\Search\SearchServiceInterface::class,
\Codappix\SearchCore\Domain\Search\CachedSearchService::class
);
} }
})($_EXTKEY, $_EXTCONF); })($_EXTKEY, $_EXTCONF);