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

Repaired quicktips

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