Skip to content
Snippets Groups Projects
Commit 816f3429 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

reduced requests to the cache

parent 4c43835e
No related branches found
No related tags found
3 merge requests!1509Development,!1508Development,!1507Resolve "Implement Timing output"
...@@ -634,10 +634,36 @@ class MetaGer ...@@ -634,10 +634,36 @@ class MetaGer
public function startSearch(&$timings) 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 # Wir starten alle Suchen
foreach ($this->engines as $engine) { foreach ($this->engines as $engine) {
$engine->startSearch($this, $timings); $engine->startSearch($this, $timings);
} }
if (!empty($timings)) {
$timings["startSearch"]["searches started"] = microtime(true) - $timings["starttime"];
}
} }
# Spezielle Suchen und Sumas # Spezielle Suchen und Sumas
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace App\Models; namespace App\Models;
use App\MetaGer; use App\MetaGer;
use Cache;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
abstract class Searchengine abstract class Searchengine
...@@ -111,17 +110,7 @@ abstract class Searchengine ...@@ -111,17 +110,7 @@ abstract class Searchengine
$timings["startSearch"][$this->name]["start"] = microtime(true) - $timings["starttime"]; $timings["startSearch"][$this->name]["start"] = microtime(true) - $timings["starttime"];
} }
if ($this->canCache && Cache::has($this->hash)) { if (!$this->cached) {
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 (!empty($timings)) { if (!empty($timings)) {
$timings["startSearch"][$this->name]["checked cache"] = microtime(true) - $timings["starttime"]; $timings["startSearch"][$this->name]["checked cache"] = microtime(true) - $timings["starttime"];
} }
...@@ -193,15 +182,13 @@ abstract class Searchengine ...@@ -193,15 +182,13 @@ abstract class Searchengine
} }
# Fragt die Ergebnisse von Redis ab und lädt Sie # 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) { if ($this->loaded) {
return true; return true;
} }
$body = null;
if ($this->cached) { if ($this->cached) {
$body = Cache::get($this->hash);
if ($body === "no-result") { if ($body === "no-result") {
$body = ""; $body = "";
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment