Commit 6ba2274c authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

fixed adgoal when no public/private key available

parent c3d3a60c
...@@ -97,10 +97,7 @@ class MetaGerSearch extends Controller ...@@ -97,10 +97,7 @@ class MetaGerSearch extends Controller
} }
# Ergebnisse der Suchmaschinen kombinieren: # Ergebnisse der Suchmaschinen kombinieren:
$metager->prepareResults(); $metager->prepareResults($timings);
if (!empty($timings)) {
$timings["prepareResults"] = microtime(true) - $time;
}
$finished = true; $finished = true;
foreach ($metager->getEngines() as $engine) { foreach ($metager->getEngines() as $engine) {
...@@ -213,7 +210,7 @@ class MetaGerSearch extends Controller ...@@ -213,7 +210,7 @@ class MetaGerSearch extends Controller
$metager->setApiAuthorized($mg["apiAuthorized"]); $metager->setApiAuthorized($mg["apiAuthorized"]);
$metager->setAdgoalLoaded($adgoal["loaded"]); $metager->setAdgoalLoaded($adgoal["loaded"]);
$metager->setAdgoalHash($adgoal["adgoalHash"]); $metager->setAdgoalHash($adgoal["adgoalHash"]);
$metager->parseFormData($request); $metager->parseFormData($request);
# Nach Spezialsuchen überprüfen: # Nach Spezialsuchen überprüfen:
$metager->checkSpecialSearches($request); $metager->checkSpecialSearches($request);
......
...@@ -252,11 +252,14 @@ class MetaGer ...@@ -252,11 +252,14 @@ class MetaGer
} }
} }
public function prepareResults() public function prepareResults(&$timings = null)
{ {
$engines = $this->engines; $engines = $this->engines;
// combine // combine
$this->combineResults($engines); $this->combineResults($engines);
if(!empty($timings)){
$timings["prepareResults"]["combined results"] = microtime(true) - $timings["starttime"];
}
// misc (WiP) // misc (WiP)
if ($this->fokus == "nachrichten") { if ($this->fokus == "nachrichten") {
$this->results = array_filter($this->results, function ($v, $k) { $this->results = array_filter($this->results, function ($v, $k) {
...@@ -276,7 +279,9 @@ class MetaGer ...@@ -276,7 +279,9 @@ class MetaGer
return ($a->getRank() < $b->getRank()) ? 1 : -1; return ($a->getRank() < $b->getRank()) ? 1 : -1;
}); });
} }
if(!empty($timings)){
$timings["prepareResults"]["sorted results"] = microtime(true) - $timings["starttime"];
}
# Validate Results # Validate Results
$newResults = []; $newResults = [];
foreach ($this->results as $result) { foreach ($this->results as $result) {
...@@ -285,7 +290,9 @@ class MetaGer ...@@ -285,7 +290,9 @@ class MetaGer
} }
} }
$this->results = $newResults; $this->results = $newResults;
if(!empty($timings)){
$timings["prepareResults"]["validated results"] = microtime(true) - $timings["starttime"];
}
# Validate Advertisements # Validate Advertisements
$newResults = []; $newResults = [];
foreach ($this->ads as $ad) { foreach ($this->ads as $ad) {
...@@ -298,7 +305,9 @@ class MetaGer ...@@ -298,7 +305,9 @@ class MetaGer
$newResults[] = $ad; $newResults[] = $ad;
} }
$this->ads = $newResults; $this->ads = $newResults;
if(!empty($timings)){
$timings["prepareResults"]["validated ads"] = microtime(true) - $timings["starttime"];
}
#Adgoal Implementation #Adgoal Implementation
if (empty($this->adgoalLoaded)) { if (empty($this->adgoalLoaded)) {
$this->adgoalLoaded = false; $this->adgoalLoaded = false;
...@@ -312,11 +321,20 @@ class MetaGer ...@@ -312,11 +321,20 @@ class MetaGer
} }
} }
$this->adgoalHash = $this->startAdgoal($this->results); $this->adgoalHash = $this->startAdgoal($this->results);
if(!empty($timings)){
$timings["prepareResults"]["started adgoal"] = microtime(true) - $timings["starttime"];
}
} }
if (!$this->javascript) { if (!$this->javascript) {
$this->adgoalLoaded = $this->parseAdgoal($this->results, $this->adgoalHash, true); $this->adgoalLoaded = $this->parseAdgoal($this->results, $this->adgoalHash, true);
if(!empty($timings)){
$timings["prepareResults"]["parsed adgoal"] = microtime(true) - $timings["starttime"];
}
} else { } else {
$this->adgoalLoaded = $this->parseAdgoal($this->results, $this->adgoalHash, false); $this->adgoalLoaded = $this->parseAdgoal($this->results, $this->adgoalHash, false);
if(!empty($timings)){
$timings["prepareResults"]["parsed adgoal"] = microtime(true) - $timings["starttime"];
}
} }
} else { } else {
$this->adgoalLoaded = true; $this->adgoalLoaded = true;
...@@ -325,6 +343,9 @@ class MetaGer ...@@ -325,6 +343,9 @@ class MetaGer
# Human Verification # Human Verification
$this->humanVerification($this->results); $this->humanVerification($this->results);
$this->humanVerification($this->ads); $this->humanVerification($this->ads);
if(!empty($timings)){
$timings["prepareResults"]["human verification"] = microtime(true) - $timings["starttime"];
}
$counter = 0; $counter = 0;
$firstRank = 0; $firstRank = 0;
...@@ -345,6 +366,9 @@ class MetaGer ...@@ -345,6 +366,9 @@ class MetaGer
'engines' => $this->next, 'engines' => $this->next,
]; ];
Cache::put($this->getSearchUid(), serialize($this->next), 60 * 60); Cache::put($this->getSearchUid(), serialize($this->next), 60 * 60);
if(!empty($timings)){
$timings["prepareResults"]["filled cache"] = microtime(true) - $timings["starttime"];
}
} else { } else {
$this->next = []; $this->next = [];
} }
...@@ -375,7 +399,7 @@ class MetaGer ...@@ -375,7 +399,7 @@ class MetaGer
$publicKey = getenv('adgoal_public'); $publicKey = getenv('adgoal_public');
$privateKey = getenv('adgoal_private'); $privateKey = getenv('adgoal_private');
if ($publicKey === false) { if ($publicKey === false) {
return null; return true;
} }
$tldList = ""; $tldList = "";
foreach ($results as $result) { foreach ($results as $result) {
...@@ -393,7 +417,7 @@ class MetaGer ...@@ -393,7 +417,7 @@ class MetaGer
# Hashwert # Hashwert
$hash = md5("meta" . $publicKey . $tldList . "GER"); $hash = md5("meta" . $publicKey . $tldList . "GER");
# Query # Query
$query = $this->q; $query = $this->q;
...@@ -422,6 +446,11 @@ class MetaGer ...@@ -422,6 +446,11 @@ class MetaGer
$startTime = microtime(true); $startTime = microtime(true);
$answer = null; $answer = null;
# Hash is true if Adgoal request wasn't started in the first place
if($hash === true){
return true;
}
if ($waitForResult) { if ($waitForResult) {
while (microtime(true) - $startTime < 5) { while (microtime(true) - $startTime < 5) {
$answer = Redis::get($hash); $answer = Redis::get($hash);
......
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