mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-30 06:50:49 +00:00 
			
		
		
		
	Add cache to search.
This commit is contained in:
		| @@ -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]); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user