diff --git a/CHANGES.md b/CHANGES.md index 268aa3049d..1317a34803 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,6 @@ # Version 0.10.3 + +## Bugs - Fixed memory leak in realtime service (#1606) - Fixed function execution output now being UTF-8 encoded before saved (#1607) diff --git a/app/realtime.php b/app/realtime.php index 40537ea615..70eacc0d4a 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -103,8 +103,6 @@ $server->onStart(function () use ($stats, $register, $containerId, &$documentId) * Save current connections to the Database every 5 seconds. */ Timer::tick(5000, function () use ($stats, $getConsoleDb, $containerId, &$documentId) { - [$consoleDb, $returnConsoleDb] = call_user_func($getConsoleDb); - foreach ($stats as $projectId => $value) { if (empty($value['connections']) && empty($value['messages'])) { continue; @@ -129,8 +127,6 @@ $server->onStart(function () use ($stats, $register, $containerId, &$documentId) if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') { $usage->trigger(); } - - unset($usage, $connections, $messages); } $payload = []; foreach ($stats as $projectId => $value) { @@ -141,19 +137,21 @@ $server->onStart(function () use ($stats, $register, $containerId, &$documentId) if (empty($payload)) { return; } - $document = [ - '$id' => $documentId, - '$collection' => Database::SYSTEM_COLLECTION_CONNECTIONS, - '$permissions' => [ - 'read' => ['*'], - 'write' => ['*'], - ], - 'container' => $containerId, - 'timestamp' => time(), - 'value' => json_encode($payload) - ]; + try { - $document = $consoleDb->updateDocument($document); + [$consoleDb, $returnConsoleDb] = call_user_func($getConsoleDb); + + $consoleDb->updateDocument([ + '$id' => $documentId, + '$collection' => Database::SYSTEM_COLLECTION_CONNECTIONS, + '$permissions' => [ + 'read' => ['*'], + 'write' => ['*'], + ], + 'container' => $containerId, + 'timestamp' => time(), + 'value' => json_encode($payload) + ]); } catch (\Throwable $th) { Console::error('[Error] Type: ' . get_class($th)); Console::error('[Error] Message: ' . $th->getMessage());