mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-09 23:15:45 -06:00
Add cache to search.
This commit is contained in:
parent
1217ff7a7f
commit
78584c7128
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use FireflyIII\Support\Search\SearchInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Response;
|
||||
@ -75,11 +76,25 @@ class SearchController extends Controller
|
||||
{
|
||||
$fullQuery = strval($request->get('query'));
|
||||
|
||||
// parse search terms:
|
||||
$searcher->parseQuery($fullQuery);
|
||||
$searcher->setLimit(20);
|
||||
$transactions = $searcher->searchTransactions();
|
||||
$html = view('search.search', compact('transactions'))->render();
|
||||
// cache
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('search');
|
||||
$cache->addProperty($fullQuery);
|
||||
|
||||
if ($cache->has()) {
|
||||
$transactions = $cache->get();
|
||||
}
|
||||
|
||||
if (!$cache->has()) {
|
||||
// parse search terms:
|
||||
$searcher->parseQuery($fullQuery);
|
||||
$searcher->setLimit(20);
|
||||
$transactions = $searcher->searchTransactions();
|
||||
$cache->store($transactions);
|
||||
}
|
||||
|
||||
|
||||
$html = view('search.search', compact('transactions'))->render();
|
||||
|
||||
return Response::json(['count' => $transactions->count(), 'html' => $html]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user