Commit 40a4c53a authored by Dominik Hebeler's avatar Dominik Hebeler

Merge branch '1024-optimize-request-fetcher' into 'development'

Resolve "Optimize Request fetcher"

Closes #1024

See merge request !1706
parents 11f21266 44e48c90
...@@ -44,6 +44,9 @@ class AdminSpamController extends Controller ...@@ -44,6 +44,9 @@ class AdminSpamController extends Controller
public function jsonQueries() public function jsonQueries()
{ {
$queries = $this->getQueries(); $queries = $this->getQueries();
# JSON encoding will fail if invalid UTF-8 Characters are in this string
# mb_convert_encoding will remove thise invalid characters for us
$queries = mb_convert_encoding($queries, "UTF-8", "UTF-8");
return response()->json($queries); return response()->json($queries);
} }
...@@ -77,8 +80,10 @@ class AdminSpamController extends Controller ...@@ -77,8 +80,10 @@ class AdminSpamController extends Controller
]; ];
} }
# JSON encoding will fail if invalid UTF-8 Characters are in this string
# mb_convert_encoding will remove thise invalid characters for us
$resultData = mb_convert_encoding($resultData, "UTF-8", "UTF-8");
return response()->json($resultData); return response()->json($resultData);
} }
private function getQueries() private function getQueries()
......
...@@ -12,7 +12,6 @@ use View; ...@@ -12,7 +12,6 @@ use View;
class MetaGerSearch extends Controller class MetaGerSearch extends Controller
{ {
public function search(Request $request, MetaGer $metager, $timing = false) public function search(Request $request, MetaGer $metager, $timing = false)
{ {
if ($request->filled("chrome-plugin")) { if ($request->filled("chrome-plugin")) {
...@@ -156,7 +155,7 @@ class MetaGerSearch extends Controller ...@@ -156,7 +155,7 @@ class MetaGerSearch extends Controller
// This might speed up page view time for users with slow network // This might speed up page view time for users with slow network
$responseArray = str_split($resultpage->render(), 1024); $responseArray = str_split($resultpage->render(), 1024);
foreach ($responseArray as $responsePart) { foreach ($responseArray as $responsePart) {
echo ($responsePart); echo($responsePart);
flush(); flush();
} }
$requestTime = microtime(true) - $time; $requestTime = microtime(true) - $time;
...@@ -182,7 +181,6 @@ class MetaGerSearch extends Controller ...@@ -182,7 +181,6 @@ class MetaGerSearch extends Controller
if ($request->filled('loadMore') && $request->filled('script') && $request->input('script') === "yes") { if ($request->filled('loadMore') && $request->filled('script') && $request->input('script') === "yes") {
return $this->loadMoreJS($request); return $this->loadMoreJS($request);
} }
} }
private function loadMoreJS(Request $request) private function loadMoreJS(Request $request)
...@@ -296,6 +294,10 @@ class MetaGerSearch extends Controller ...@@ -296,6 +294,10 @@ class MetaGerSearch extends Controller
], ],
"engines" => $metager->getEngines(), "engines" => $metager->getEngines(),
], 1 * 60); ], 1 * 60);
# JSON encoding will fail if invalid UTF-8 Characters are in this string
# mb_convert_encoding will remove thise invalid characters for us
$result = mb_convert_encoding($result, "UTF-8", "UTF-8");
return response()->json($result); return response()->json($result);
} }
......
...@@ -5,6 +5,7 @@ namespace App\Http\Middleware; ...@@ -5,6 +5,7 @@ namespace App\Http\Middleware;
use Closure; use Closure;
use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Redis;
use Jenssegers\Agent\Agent; use Jenssegers\Agent\Agent;
use Cache;
class BrowserVerification class BrowserVerification
{ {
...@@ -59,12 +60,12 @@ class BrowserVerification ...@@ -59,12 +60,12 @@ class BrowserVerification
$key = md5($request->ip() . microtime(true)); $key = md5($request->ip() . microtime(true));
echo (view('layouts.resultpage.verificationHeader')->with('key', $key)->render()); echo(view('layouts.resultpage.verificationHeader')->with('key', $key)->render());
flush(); flush();
$answer = Redis::connection("cache")->blpop($key, 2); $answer = Redis::connection("cache")->blpop($key, 2);
if ($answer !== null) { if ($answer !== null) {
echo (view('layouts.resultpage.resources')->render()); echo(view('layouts.resultpage.resources')->render());
flush(); flush();
$request->request->add(["headerPrinted" => true, "jskey" => $key]); $request->request->add(["headerPrinted" => true, "jskey" => $key]);
return $next($request); return $next($request);
...@@ -74,9 +75,8 @@ class BrowserVerification ...@@ -74,9 +75,8 @@ class BrowserVerification
$params["mgv"] = $key; $params["mgv"] = $key;
$url = route("resultpage", $params); $url = route("resultpage", $params);
echo (view('layouts.resultpage.unverifiedResultPage') echo(view('layouts.resultpage.unverifiedResultPage')
->with('url', $url) ->with('url', $url)
->render()); ->render());
} }
} }
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