Commit 09827c47 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Repaired quicktips

parent abf7782c
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace App\Models\Quicktips; namespace App\Models\Quicktips;
use App\Jobs\Searcher; use Cache;
use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use Log; use Log;
...@@ -30,41 +30,23 @@ class Quicktips ...@@ -30,41 +30,23 @@ class Quicktips
public function startSearch($search, $locale, $max_time) public function startSearch($search, $locale, $max_time)
{ {
$url = $this->quicktipUrl . "?search=" . $this->normalize_search($search) . "&locale=" . $locale; $url = $this->quicktipUrl . "?search=" . $this->normalize_search($search) . "&locale=" . $locale;
# TODO anders weitergeben
$this->hash = md5($url); $this->hash = md5($url);
# TODO cache wieder einbauen (eventuell) if (!Cache::has($this->hash)) {
if ( /*!Cache::has($hash)*/true) {
$redis = Redis::connection(env('REDIS_RESULT_CONNECTION'));
$redis->hset("search." . $this->hash . ".results." . self::QUICKTIP_NAME, "status", "waiting");
// Queue this search // Queue this search
$mission = $this->hash . ";" . base64_encode($url) . ";" . $max_time; $mission = [
Redis::rpush(self::QUICKTIP_NAME . ".queue", $mission); "resulthash" => $this->hash,
"url" => $url,
// Check the current status of Searchers for QUICKTIP_NAME "username" => null,
$needSearcher = false; "password" => null,
$searcherData = Redis::hgetall(self::QUICKTIP_NAME . ".stats"); "headers" => [],
"cacheDuration" => self::CACHE_DURATION,
// Create additional Searchers for QUICKTIP_NAME if necessary ];
if (sizeof($searcherData) === 0) {
$needSearcher = true; $mission = json_encode($mission);
} else {
$median = 0; Redis::rpush(\App\MetaGer::FETCHQUEUE_KEY, $mission);
foreach ($searcherData as $pid => $data) {
$data = explode(";", $data);
$median += floatval($data[1]);
}
$median /= sizeof($searcherData);
if ($median < .1) {
$needSearcher = true;
}
}
if ($needSearcher && Redis::get(self::QUICKTIP_NAME) !== "locked") {
Redis::set(self::QUICKTIP_NAME, "locked");
$this->dispatch(new Searcher(self::QUICKTIP_NAME));
}
} }
} }
...@@ -87,13 +69,13 @@ class Quicktips ...@@ -87,13 +69,13 @@ class Quicktips
public function retrieveResults($hash) public function retrieveResults($hash)
{ {
$body = ""; $body = null;
$redis = Redis::connection(env('REDIS_RESULT_CONNECTION'));
$body = $redis->hget('search.' . $hash . ".results." . self::QUICKTIP_NAME, "response"); if (Cache::has($this->hash)) {
$body = Cache::get($this->hash);
}
$redis->del('search.' . $hash . ".results." . self::QUICKTIP_NAME); if ($body !== null) {
$redis->del('search.' . $hash . ".ready");
if ($body !== "") {
return $body; return $body;
} else { } else {
return false; return false;
......
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