Commit f7b052c3 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

fixed async adgoal error

parent e3ba9215
......@@ -2,6 +2,7 @@
namespace App\Console\Commands;
use Cache;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;
use Log;
......@@ -25,7 +26,7 @@ class RequestFetcher extends Command
protected $shouldRun = true;
protected $multicurl = null;
protected $oldMultiCurl = null;
protected $maxFetchedDocuments = 10000;
protected $maxFetchedDocuments = 100000;
protected $fetchedDocuments = 0;
protected $proxyhost, $proxyuser, $proxypassword;
......@@ -170,10 +171,14 @@ class RequestFetcher extends Command
$pipe->set($resulthash, $body);
$pipe->expire($resulthash, 60);
});
/*
if ($cacheDurationMinutes > 0) {
Cache::put($resulthash, $body, $cacheDurationMinutes * 60);
}*/
if ($cacheDurationMinutes > 0) {
try {
Cache::put($resulthash, $body, $cacheDurationMinutes * 60);
} catch (\Exception $e) {
Log::error($e->getMessage());
}
}
} finally {
\curl_multi_remove_handle($mc, $info["handle"]);
}
......
......@@ -219,6 +219,9 @@ class MetaGerSearch extends Controller
$metager->checkSpecialSearches($request);
$metager->restoreEngines($engines);
# Checks Cache for engine Results
$metager->checkCache();
$metager->retrieveResults();
$metager->rankAll();
......@@ -258,10 +261,13 @@ class MetaGerSearch extends Controller
}
$finished = true;
$enginesLoaded = [];
foreach ($engines as $engine) {
if (!$engine->loaded) {
$enginesLoaded[$engine->name] = false;
$finished = false;
} else {
$enginesLoaded[$engine->name] = true;
$engine->setNew(false);
$engine->markNew();
}
......@@ -273,6 +279,7 @@ class MetaGerSearch extends Controller
*/
$result["finished"] = $finished;
$result["engines"] = $enginesLoaded;
if ($newResults > 0) {
$registry = \Prometheus\CollectorRegistry::getDefault();
......
......@@ -307,7 +307,7 @@ class MetaGer
if (empty($this->adgoalHash)) {
$this->adgoalHash = $this->startAdgoal($this->results);
}
if (!$this->javascript || 1 == 1) {
if (!$this->javascript) {
$this->adgoalLoaded = $this->parseAdgoal($this->results, $this->adgoalHash, true);
} else {
$this->adgoalLoaded = $this->parseAdgoal($this->results, $this->adgoalHash, false);
......@@ -693,6 +693,24 @@ class MetaGer
}
# Check all engines for Cached responses
$this->checkCache();
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"];
}
}
public function checkCache()
{
if ($this->canCache()) {
$keys = [];
foreach ($this->engines as $engine) {
......@@ -706,17 +724,6 @@ class MetaGer
}
}
}
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"];
}
}
......@@ -1934,8 +1941,5 @@ class MetaGer
public function restoreEngines($engines)
{
$this->engines = $engines;
foreach ($this->engines as $engine) {
$engine->setCached(true);
}
}
}
......@@ -3,9 +3,7 @@
namespace App\Models;
use App\MetaGer;
use Cache;
use Illuminate\Support\Facades\Redis;
use Log;
abstract class Searchengine
{
......@@ -199,22 +197,14 @@ abstract class Searchengine
return true;
}
if ($this->cached) {
if ($body === "no-result") {
$body = "";
}
} else {
if (!$this->cached) {
$body = Redis::get($this->hash);
}
if ($body === "no-result") {
$body = "";
}
if ($body !== null) {
if (!$this->cached) {
try {
Cache::put($this->hash, $body, $this->cacheDuration * 60);
} catch (\Exception $e) {
Log::error($e->getMessage());
}
}
$this->loadResults($body);
$this->getNext($metager, $body);
$this->markNew();
......
Supports Markdown
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