Skip to content

Firefly III: a personal finances manager

Add cache to search.

James Cole78584c7128d6
diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php
index 39acf95596..0ba7e68a7b 100644
--- a/app/Http/Controllers/SearchController.php
+++ b/app/Http/Controllers/SearchController.php
@@ -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]);