1
0
Fork 0
mirror of synced 2024-05-20 12:42:39 +12:00

Merge pull request #1627 from TorstenDittmann/fix-realtime-memory-leak-2

fix(realtime): memory leak #2
This commit is contained in:
Torsten Dittmann 2021-09-15 16:03:18 +02:00 committed by GitHub
commit 1fbb37b983
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 16 deletions

View file

@ -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)

View file

@ -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());