Skip to content
Snippets Groups Projects
Commit 6e369379 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

store logs in new more performant table

parent 8d834c05
No related branches found
No related tags found
1 merge request!2234store logs in new more performant table
...@@ -56,7 +56,7 @@ class AdminInterface extends Controller ...@@ -56,7 +56,7 @@ class AdminInterface extends Controller
public function getCountData(Request $request) public function getCountData(Request $request)
{ {
$date = $request->input('date', ''); $date = $request->input('date', '');
$date = Carbon::createFromFormat("Y-m-d H:i:s", "$date 00:00:00"); $date = Carbon::createFromFormat("Y-m-d H:i:s", "$date 00:00:00", 'UTC');
if ($date === false) { if ($date === false) {
abort(404); abort(404);
} }
...@@ -66,7 +66,7 @@ class AdminInterface extends Controller ...@@ -66,7 +66,7 @@ class AdminInterface extends Controller
$connection = DB::connection("logs"); $connection = DB::connection("logs");
$log_summary = $connection $log_summary = $connection
->table( ->table(
$connection->table("logs")->select(["*"])->whereRaw("(time at time zone 'UTC') between '" . $date->format("Y-m-d") . " 00:00:00' and '" . $date->format("Y-m-d") . " 23:59:59'"), $connection->table("logs_partitioned")->select(["*"])->whereRaw("time between '" . $date->format("Y-m-d") . " 00:00:00' and '" . $date->format("Y-m-d") . " 23:59:59'"),
"data" "data"
) )
->select(DB::raw("date_trunc('hour', data.time) AS timestamp, count(*)")) ->select(DB::raw("date_trunc('hour', data.time) AS timestamp, count(*)"))
...@@ -89,9 +89,9 @@ class AdminInterface extends Controller ...@@ -89,9 +89,9 @@ class AdminInterface extends Controller
"until_now" => 0 "until_now" => 0
]; ];
$now = Carbon::now(); $now = Carbon::now("UTC");
foreach ($log_summary as $entry) { foreach ($log_summary as $entry) {
$time = Carbon::createFromFormat("Y-m-d H:i:sO", $entry->timestamp); $time = Carbon::createFromFormat("Y-m-d H:i:s", $entry->timestamp, "UTC");
$time->day(1)->year($now->year)->month($now->month)->day($now->day); $time->day(1)->year($now->year)->month($now->month)->day($now->day);
$result["total"] += $entry->count; $result["total"] += $entry->count;
if ($time->isBefore($now)) { if ($time->isBefore($now)) {
......
...@@ -139,7 +139,7 @@ class QueryLogger ...@@ -139,7 +139,7 @@ class QueryLogger
} }
if (sizeof($insert_array) > 0) { if (sizeof($insert_array) > 0) {
return DB::connection("logs")->table("logs")->insert($insert_array); return DB::connection("logs")->table("logs_partitioned")->insert($insert_array);
} }
return false; return false;
} }
...@@ -156,8 +156,8 @@ class QueryLogger ...@@ -156,8 +156,8 @@ class QueryLogger
$connection = DB::connection("logs"); $connection = DB::connection("logs");
$since->setTimezone("UTC"); // We will query in UTC time $since->setTimezone("UTC"); // We will query in UTC time
$queries = $connection->table("logs") $queries = $connection->table("logs_partitioned")
->whereRaw("(time at time zone 'UTC') > '" . $since->format("Y-m-d H:i:s") . "'") ->whereRaw("time > '" . $since->format("Y-m-d H:i:s") . "'")
->orderBy("time", "asc") ->orderBy("time", "asc")
->get(); ->get();
return $queries; return $queries;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment