Merge branch '1.6.x' into fix-messaging-test-for-audits

This commit is contained in:
Christy Jacob 2025-01-10 14:50:23 +05:30 committed by GitHub
commit 595e93e59e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 48 additions and 98 deletions

View file

@ -21,7 +21,6 @@ use Appwrite\Utopia\Response\Filters\V18 as ResponseV18;
use Appwrite\Utopia\View; use Appwrite\Utopia\View;
use Executor\Executor; use Executor\Executor;
use MaxMind\Db\Reader; use MaxMind\Db\Reader;
use Swoole\Database\DetectsLostConnections;
use Swoole\Http\Request as SwooleRequest; use Swoole\Http\Request as SwooleRequest;
use Utopia\App; use Utopia\App;
use Utopia\CLI\Console; use Utopia\CLI\Console;
@ -29,7 +28,6 @@ use Utopia\Config\Config;
use Utopia\Database\Database; use Utopia\Database\Database;
use Utopia\Database\DateTime; use Utopia\Database\DateTime;
use Utopia\Database\Document; use Utopia\Database\Document;
use Utopia\Database\Exception as DatabaseException;
use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\ID;
use Utopia\Database\Query; use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Authorization;
@ -40,7 +38,6 @@ use Utopia\Logger\Adapter\Sentry;
use Utopia\Logger\Log; use Utopia\Logger\Log;
use Utopia\Logger\Log\User; use Utopia\Logger\Log\User;
use Utopia\Logger\Logger; use Utopia\Logger\Logger;
use Utopia\Pools\Connection;
use Utopia\System\System; use Utopia\System\System;
use Utopia\Validator\Hostname; use Utopia\Validator\Hostname;
use Utopia\Validator\Text; use Utopia\Validator\Text;
@ -749,16 +746,7 @@ App::error()
->inject('logger') ->inject('logger')
->inject('log') ->inject('log')
->inject('queueForUsage') ->inject('queueForUsage')
->inject('connectionForProject') ->action(function (Throwable $error, App $utopia, Request $request, Response $response, Document $project, ?Logger $logger, Log $log, Usage $queueForUsage) {
->action(function (Throwable $error, App $utopia, Request $request, Response $response, Document $project, ?Logger $logger, Log $log, Usage $queueForUsage, Connection $connectionForProject) {
if (
($error instanceof PDOException || $error instanceof DatabaseException)
&& DetectsLostConnections::causedByLostConnection($error)
) {
// Mark connection as unhealthy so it will be recycled on next reclaim.
$connectionForProject->setHealthy(false);
}
$version = System::getEnv('_APP_VERSION', 'UNKNOWN'); $version = System::getEnv('_APP_VERSION', 'UNKNOWN');
$route = $utopia->getRoute(); $route = $utopia->getRoute();
$class = \get_class($error); $class = \get_class($error);

View file

@ -5,7 +5,6 @@ require_once __DIR__ . '/../vendor/autoload.php';
use Appwrite\Utopia\Request; use Appwrite\Utopia\Request;
use Appwrite\Utopia\Response; use Appwrite\Utopia\Response;
use Swoole\Constant; use Swoole\Constant;
use Swoole\Database\DetectsLostConnections;
use Swoole\Http\Request as SwooleRequest; use Swoole\Http\Request as SwooleRequest;
use Swoole\Http\Response as SwooleResponse; use Swoole\Http\Response as SwooleResponse;
use Swoole\Http\Server; use Swoole\Http\Server;
@ -18,7 +17,6 @@ use Utopia\Config\Config;
use Utopia\Database\Database; use Utopia\Database\Database;
use Utopia\Database\DateTime; use Utopia\Database\DateTime;
use Utopia\Database\Document; use Utopia\Database\Document;
use Utopia\Database\Exception as DatabaseException;
use Utopia\Database\Exception\Duplicate; use Utopia\Database\Exception\Duplicate;
use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\ID;
use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Permission;
@ -348,15 +346,6 @@ $http->on(Constant::EVENT_REQUEST, function (SwooleRequest $swooleRequest, Swool
$app->run($request, $response); $app->run($request, $response);
} catch (\Throwable $th) { } catch (\Throwable $th) {
if (
($th instanceof PDOException || $th instanceof DatabaseException)
&& DetectsLostConnections::causedByLostConnection($th)
) {
// Mark connection as unhealthy so it will be recycled on next reclaim.
$connectionForProject = $app->getResource('connectionForProject');
$connectionForProject->setHealthy(false);
}
$version = System::getEnv('_APP_VERSION', 'UNKNOWN'); $version = System::getEnv('_APP_VERSION', 'UNKNOWN');
$logger = $app->getResource("logger"); $logger = $app->getResource("logger");

View file

@ -74,7 +74,6 @@ use Utopia\Logger\Adapter\Raygun;
use Utopia\Logger\Adapter\Sentry; use Utopia\Logger\Adapter\Sentry;
use Utopia\Logger\Log; use Utopia\Logger\Log;
use Utopia\Logger\Logger; use Utopia\Logger\Logger;
use Utopia\Pools\Connection as PoolConnection;
use Utopia\Pools\Group; use Utopia\Pools\Group;
use Utopia\Pools\Pool; use Utopia\Pools\Pool;
use Utopia\Queue; use Utopia\Queue;
@ -1413,26 +1412,7 @@ App::setResource('console', function () {
]); ]);
}, []); }, []);
App::setResource('connectionForProject', function (Group $pools, Document $project) { App::setResource('dbForProject', function (Group $pools, Database $dbForPlatform, Cache $cache, Document $project) {
if ($project->isEmpty() || $project->getId() === 'console') {
return $pools
->get('console')
->pop();
}
try {
$dsn = new DSN($project->getAttribute('database'));
} catch (\InvalidArgumentException) {
// TODO: Temporary until all projects are using shared tables
$dsn = new DSN('mysql://' . $project->getAttribute('database'));
}
return $pools
->get($dsn->getHost())
->pop();
}, ['pools', 'project']);
App::setResource('dbForProject', function (Group $pools, PoolConnection $connectionForProject, Database $dbForPlatform, Cache $cache, Document $project) {
if ($project->isEmpty() || $project->getId() === 'console') { if ($project->isEmpty() || $project->getId() === 'console') {
return $dbForPlatform; return $dbForPlatform;
} }
@ -1444,7 +1424,12 @@ App::setResource('dbForProject', function (Group $pools, PoolConnection $connect
$dsn = new DSN('mysql://' . $project->getAttribute('database')); $dsn = new DSN('mysql://' . $project->getAttribute('database'));
} }
$database = new Database($connectionForProject->getResource(), $cache); $dbAdapter = $pools
->get($dsn->getHost())
->pop()
->getResource();
$database = new Database($dbAdapter, $cache);
$database $database
->setMetadata('host', \gethostname()) ->setMetadata('host', \gethostname())
@ -1467,7 +1452,7 @@ App::setResource('dbForProject', function (Group $pools, PoolConnection $connect
} }
return $database; return $database;
}, ['pools', 'connectionForProject', 'dbForPlatform', 'cache', 'project']); }, ['pools', 'dbForPlatform', 'cache', 'project']);
App::setResource('dbForPlatform', function (Group $pools, Cache $cache) { App::setResource('dbForPlatform', function (Group $pools, Cache $cache) {
$dbAdapter = $pools $dbAdapter = $pools

View file

@ -16,7 +16,6 @@ use Appwrite\Event\Migration;
use Appwrite\Event\Usage; use Appwrite\Event\Usage;
use Appwrite\Event\UsageDump; use Appwrite\Event\UsageDump;
use Appwrite\Platform\Appwrite; use Appwrite\Platform\Appwrite;
use Swoole\Database\DetectsLostConnections;
use Swoole\Runtime; use Swoole\Runtime;
use Utopia\Abuse\Adapters\TimeLimit\Redis as TimeLimitRedis; use Utopia\Abuse\Adapters\TimeLimit\Redis as TimeLimitRedis;
use Utopia\Cache\Adapter\Sharding; use Utopia\Cache\Adapter\Sharding;
@ -26,13 +25,11 @@ use Utopia\Config\Config;
use Utopia\Database\Database; use Utopia\Database\Database;
use Utopia\Database\DateTime; use Utopia\Database\DateTime;
use Utopia\Database\Document; use Utopia\Database\Document;
use Utopia\Database\Exception as DatabaseException;
use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Authorization;
use Utopia\DSN\DSN; use Utopia\DSN\DSN;
use Utopia\Logger\Log; use Utopia\Logger\Log;
use Utopia\Logger\Logger; use Utopia\Logger\Logger;
use Utopia\Platform\Service; use Utopia\Platform\Service;
use Utopia\Pools\Connection as PoolConnection;
use Utopia\Pools\Group; use Utopia\Pools\Group;
use Utopia\Queue\Connection; use Utopia\Queue\Connection;
use Utopia\Queue\Message; use Utopia\Queue\Message;
@ -69,13 +66,13 @@ Server::setResource('project', function (Message $message, Database $dbForPlatfo
return $dbForPlatform->getDocument('projects', $project->getId()); return $dbForPlatform->getDocument('projects', $project->getId());
}, ['message', 'dbForPlatform']); }, ['message', 'dbForPlatform']);
Server::setResource('connectionForProject', function (Group $pools, Document $project) { Server::setResource('dbForProject', function (Cache $cache, Registry $register, Message $message, Document $project, Database $dbForPlatform) {
if ($project->isEmpty() || $project->getId() === 'console') { if ($project->isEmpty() || $project->getId() === 'console') {
return $pools return $dbForPlatform;
->get('console')
->pop();
} }
$pools = $register->get('pools');
try { try {
$dsn = new DSN($project->getAttribute('database')); $dsn = new DSN($project->getAttribute('database'));
} catch (\InvalidArgumentException) { } catch (\InvalidArgumentException) {
@ -83,17 +80,12 @@ Server::setResource('connectionForProject', function (Group $pools, Document $pr
$dsn = new DSN('mysql://' . $project->getAttribute('database')); $dsn = new DSN('mysql://' . $project->getAttribute('database'));
} }
return $pools $adapter = $pools
->get($dsn->getHost()) ->get($dsn->getHost())
->pop(); ->pop()
}, ['pools', 'project']); ->getResource();
Server::setResource('dbForProject', function (PoolConnection $connectionForProject, Cache $cache, Registry $register, Message $message, Document $project, Database $dbForPlatform) { $database = new Database($adapter, $cache);
if ($project->isEmpty() || $project->getId() === 'console') {
return $dbForPlatform;
}
$database = new Database($connectionForProject->getResource(), $cache);
try { try {
$dsn = new DSN($project->getAttribute('database')); $dsn = new DSN($project->getAttribute('database'));
@ -117,12 +109,12 @@ Server::setResource('dbForProject', function (PoolConnection $connectionForProje
} }
return $database; return $database;
}, ['connectionForProject', 'cache', 'register', 'message', 'project', 'dbForPlatform']); }, ['cache', 'register', 'message', 'project', 'dbForPlatform']);
Server::setResource('getProjectDB', function (Group $pools, PoolConnection $connectionForProject, Database $dbForPlatform, $cache) { Server::setResource('getProjectDB', function (Group $pools, Database $dbForPlatform, $cache) {
$databases = []; // TODO: @Meldiron This should probably be responsibility of utopia-php/pools $databases = []; // TODO: @Meldiron This should probably be responsibility of utopia-php/pools
return function (Document $project) use ($pools, $connectionForProject, $dbForPlatform, $cache, &$databases): Database { return function (Document $project) use ($pools, $dbForPlatform, $cache, &$databases): Database {
if ($project->isEmpty() || $project->getId() === 'console') { if ($project->isEmpty() || $project->getId() === 'console') {
return $dbForPlatform; return $dbForPlatform;
} }
@ -154,7 +146,12 @@ Server::setResource('getProjectDB', function (Group $pools, PoolConnection $conn
return $database; return $database;
} }
$database = new Database($connectionForProject->getResource(), $cache); $dbAdapter = $pools
->get($dsn->getHost())
->pop()
->getResource();
$database = new Database($dbAdapter, $cache);
$databases[$dsn->getHost()] = $database; $databases[$dsn->getHost()] = $database;
@ -174,7 +171,7 @@ Server::setResource('getProjectDB', function (Group $pools, PoolConnection $conn
return $database; return $database;
}; };
}, ['pools', 'connectionForProject', 'dbForPlatform', 'cache']); }, ['pools', 'dbForPlatform', 'cache']);
Server::setResource('abuseRetention', function () { Server::setResource('abuseRetention', function () {
return time() - (int) System::getEnv('_APP_MAINTENANCE_RETENTION_ABUSE', 86400); return time() - (int) System::getEnv('_APP_MAINTENANCE_RETENTION_ABUSE', 86400);
@ -413,16 +410,7 @@ $worker
->inject('log') ->inject('log')
->inject('pools') ->inject('pools')
->inject('project') ->inject('project')
->inject('connectionForProject') ->action(function (Throwable $error, ?Logger $logger, Log $log, Group $pools, Document $project) use ($queueName) {
->action(function (Throwable $error, ?Logger $logger, Log $log, Group $pools, Document $project, PoolConnection $connectionForProject) use ($queueName) {
if (
($error instanceof PDOException || $error instanceof DatabaseException)
&& DetectsLostConnections::causedByLostConnection($error)
) {
// Mark connection as unhealthy, it will be recycled on next reclaim.
$connectionForProject->setHealthy(false);
}
$pools->reclaim(); $pools->reclaim();
$version = System::getEnv('_APP_VERSION', 'UNKNOWN'); $version = System::getEnv('_APP_VERSION', 'UNKNOWN');

View file

@ -63,7 +63,7 @@
"utopia-php/migration": "0.6.*", "utopia-php/migration": "0.6.*",
"utopia-php/orchestration": "0.9.*", "utopia-php/orchestration": "0.9.*",
"utopia-php/platform": "0.7.*", "utopia-php/platform": "0.7.*",
"utopia-php/pools": "0.6.*", "utopia-php/pools": "0.5.*",
"utopia-php/preloader": "0.2.*", "utopia-php/preloader": "0.2.*",
"utopia-php/queue": "0.7.*", "utopia-php/queue": "0.7.*",
"utopia-php/registry": "0.5.*", "utopia-php/registry": "0.5.*",

38
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "7b5b5926b452186543903eb539f59c2d", "content-hash": "6b136b5490c0d5d331eac0d70bb3e198",
"packages": [ "packages": [
{ {
"name": "adhocore/jwt", "name": "adhocore/jwt",
@ -3929,16 +3929,16 @@
}, },
{ {
"name": "utopia-php/migration", "name": "utopia-php/migration",
"version": "0.6.14", "version": "0.6.13",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/utopia-php/migration.git", "url": "https://github.com/utopia-php/migration.git",
"reference": "59a19f09ded0ccab4c8cca35b1242c01e2b9cfd2" "reference": "68d9b0a9477755afcda607e7e8109785cae17a13"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/59a19f09ded0ccab4c8cca35b1242c01e2b9cfd2", "url": "https://api.github.com/repos/utopia-php/migration/zipball/68d9b0a9477755afcda607e7e8109785cae17a13",
"reference": "59a19f09ded0ccab4c8cca35b1242c01e2b9cfd2", "reference": "68d9b0a9477755afcda607e7e8109785cae17a13",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3979,9 +3979,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/utopia-php/migration/issues", "issues": "https://github.com/utopia-php/migration/issues",
"source": "https://github.com/utopia-php/migration/tree/0.6.14" "source": "https://github.com/utopia-php/migration/tree/0.6.13"
}, },
"time": "2025-01-08T01:07:25+00:00" "time": "2024-11-26T13:57:53+00:00"
}, },
{ {
"name": "utopia-php/mongo", "name": "utopia-php/mongo",
@ -4145,25 +4145,25 @@
}, },
{ {
"name": "utopia-php/pools", "name": "utopia-php/pools",
"version": "0.6.0", "version": "0.5.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/utopia-php/pools.git", "url": "https://github.com/utopia-php/pools.git",
"reference": "59414ab7b57728edfde6d5ccc5a2583b7967ac18" "reference": "6f716a213a08db95eda1b5dddfa90983c1834817"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/utopia-php/pools/zipball/59414ab7b57728edfde6d5ccc5a2583b7967ac18", "url": "https://api.github.com/repos/utopia-php/pools/zipball/6f716a213a08db95eda1b5dddfa90983c1834817",
"reference": "59414ab7b57728edfde6d5ccc5a2583b7967ac18", "reference": "6f716a213a08db95eda1b5dddfa90983c1834817",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=8.3" "php": ">=8.0"
}, },
"require-dev": { "require-dev": {
"laravel/pint": "1.*", "laravel/pint": "1.2.*",
"phpstan/phpstan": "1.*", "phpstan/phpstan": "1.8.*",
"phpunit/phpunit": "11.*" "phpunit/phpunit": "^9.3"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -4190,9 +4190,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/utopia-php/pools/issues", "issues": "https://github.com/utopia-php/pools/issues",
"source": "https://github.com/utopia-php/pools/tree/0.6.0" "source": "https://github.com/utopia-php/pools/tree/0.5.0"
}, },
"time": "2025-01-08T07:58:42+00:00" "time": "2024-04-19T11:11:54+00:00"
}, },
{ {
"name": "utopia-php/preloader", "name": "utopia-php/preloader",
@ -8556,7 +8556,7 @@
], ],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": {}, "stability-flags": [],
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
@ -8580,5 +8580,5 @@
"platform-overrides": { "platform-overrides": {
"php": "8.3" "php": "8.3"
}, },
"plugin-api-version": "2.6.0" "plugin-api-version": "2.2.0"
} }