Commit 816f3429 authored by Dominik Hebeler's avatar Dominik Hebeler

reduced requests to the cache

parent 4c43835e
......@@ -634,10 +634,36 @@ class MetaGer
public function startSearch(&$timings)
{
if (!empty($timings)) {
$timings["startSearch"]["start"] = microtime(true) - $timings["starttime"];
}
# Check all engines for Cached responses
if ($this->canCache()) {
$keys = [];
foreach ($this->engines as $engine) {
$keys[] = $engine->hash;
}
$cacheValues = Cache::many($keys);
foreach ($this->engines as $engine) {
if ($cacheValues[$engine->hash] !== null) {
$engine->cached = true;
$engine->retrieveResults($this, $cacheValues[$engine->hash]);
}
}
}
if (!empty($timings)) {
$timings["startSearch"]["cache checked"] = microtime(true) - $timings["starttime"];
}
# Wir starten alle Suchen
foreach ($this->engines as $engine) {
$engine->startSearch($this, $timings);
}
if (!empty($timings)) {
$timings["startSearch"]["searches started"] = microtime(true) - $timings["starttime"];
}
}
# Spezielle Suchen und Sumas
......
......@@ -3,7 +3,6 @@
namespace App\Models;
use App\MetaGer;
use Cache;
use Illuminate\Support\Facades\Redis;
abstract class Searchengine
......@@ -111,17 +110,7 @@ abstract class Searchengine
$timings["startSearch"][$this->name]["start"] = microtime(true) - $timings["starttime"];
}
if ($this->canCache && Cache::has($this->hash)) {
if (!empty($timings)) {
$timings["startSearch"][$this->name]["checked cache"] = microtime(true) - $timings["starttime"];
}
$this->cached = true;
$this->retrieveResults($metager, true);
if (!empty($timings)) {
$timings["startSearch"][$this->name]["retrieved results"] = microtime(true) - $timings["starttime"];
}
} else {
if (!$this->cached) {
if (!empty($timings)) {
$timings["startSearch"][$this->name]["checked cache"] = microtime(true) - $timings["starttime"];
}
......@@ -193,15 +182,13 @@ abstract class Searchengine
}
# Fragt die Ergebnisse von Redis ab und lädt Sie
public function retrieveResults(MetaGer $metager)
public function retrieveResults(MetaGer $metager, $body = null)
{
if ($this->loaded) {
return true;
}
$body = null;
if ($this->cached) {
$body = Cache::get($this->hash);
if ($body === "no-result") {
$body = "";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment