From 3e2c4b9fdf53361296410422c350e880368b74df Mon Sep 17 00:00:00 2001 From: prateek banga Date: Tue, 8 Aug 2023 16:38:12 +0530 Subject: [PATCH] rename setTimeout methods --- composer.lock | 79 ++++++++++++++++--------------- src/Database/Adapter.php | 4 +- src/Database/Adapter/MariaDB.php | 8 ++-- src/Database/Adapter/MySQL.php | 2 +- src/Database/Adapter/Postgres.php | 8 ++-- src/Database/Database.php | 8 ++-- tests/Database/Base.php | 4 +- 7 files changed, 57 insertions(+), 56 deletions(-) diff --git a/composer.lock b/composer.lock index ce55d7f30..d42fcea85 100644 --- a/composer.lock +++ b/composer.lock @@ -336,16 +336,16 @@ }, { "name": "utopia-php/framework", - "version": "0.28.4", + "version": "0.30.0", "source": { "type": "git", "url": "https://github.com/utopia-php/framework.git", - "reference": "98c5469efe195aeecc63745dbf8e2f357f8cedac" + "reference": "0969d429997996ceade53e477fce31221b415651" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/98c5469efe195aeecc63745dbf8e2f357f8cedac", - "reference": "98c5469efe195aeecc63745dbf8e2f357f8cedac", + "url": "https://api.github.com/repos/utopia-php/framework/zipball/0969d429997996ceade53e477fce31221b415651", + "reference": "0969d429997996ceade53e477fce31221b415651", "shasum": "" }, "require": { @@ -353,9 +353,9 @@ }, "require-dev": { "laravel/pint": "^1.2", - "phpstan/phpstan": "1.9.x-dev", - "phpunit/phpunit": "^9.5.25", - "vimeo/psalm": "4.27.0" + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^9.5.25" }, "type": "library", "autoload": { @@ -375,9 +375,9 @@ ], "support": { "issues": "https://github.com/utopia-php/framework/issues", - "source": "https://github.com/utopia-php/framework/tree/0.28.4" + "source": "https://github.com/utopia-php/framework/tree/0.30.0" }, - "time": "2023-06-03T14:09:22+00:00" + "time": "2023-08-07T07:55:48+00:00" }, { "name": "utopia-php/mongo", @@ -706,16 +706,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.15.5", + "version": "v4.16.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e" + "reference": "19526a33fb561ef417e822e85f08a00db4059c17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/11e2663a5bc9db5d714eedb4277ee300403b4a9e", - "reference": "11e2663a5bc9db5d714eedb4277ee300403b4a9e", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/19526a33fb561ef417e822e85f08a00db4059c17", + "reference": "19526a33fb561ef417e822e85f08a00db4059c17", "shasum": "" }, "require": { @@ -756,9 +756,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.5" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.16.0" }, - "time": "2023-05-19T20:20:00+00:00" + "time": "2023-06-25T14:52:30+00:00" }, { "name": "pcov/clobber", @@ -907,16 +907,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.18", + "version": "1.10.27", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "52b6416c579663eebdd2f1d97df21971daf3b43f" + "reference": "a9f44dcea06f59d1363b100bb29f297b311fa640" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/52b6416c579663eebdd2f1d97df21971daf3b43f", - "reference": "52b6416c579663eebdd2f1d97df21971daf3b43f", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/a9f44dcea06f59d1363b100bb29f297b311fa640", + "reference": "a9f44dcea06f59d1363b100bb29f297b311fa640", "shasum": "" }, "require": { @@ -965,20 +965,20 @@ "type": "tidelift" } ], - "time": "2023-06-07T22:00:43+00:00" + "time": "2023-08-05T09:57:55+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.26", + "version": "9.2.27", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1" + "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/443bc6912c9bd5b409254a40f4b0f4ced7c80ea1", - "reference": "443bc6912c9bd5b409254a40f4b0f4ced7c80ea1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/b0a88255cb70d52653d80c890bd7f38740ea50d1", + "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1", "shasum": "" }, "require": { @@ -1034,7 +1034,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.26" + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.27" }, "funding": [ { @@ -1042,7 +1043,7 @@ "type": "github" } ], - "time": "2023-03-06T12:58:08+00:00" + "time": "2023-07-26T13:44:30+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1287,16 +1288,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.9", + "version": "9.6.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a9aceaf20a682aeacf28d582654a1670d8826778" + "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a9aceaf20a682aeacf28d582654a1670d8826778", - "reference": "a9aceaf20a682aeacf28d582654a1670d8826778", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a6d351645c3fe5a30f5e86be6577d946af65a328", + "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328", "shasum": "" }, "require": { @@ -1370,7 +1371,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.9" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.10" }, "funding": [ { @@ -1386,7 +1387,7 @@ "type": "tidelift" } ], - "time": "2023-06-11T06:13:56+00:00" + "time": "2023-07-10T04:04:23+00:00" }, { "name": "psr/container", @@ -1993,16 +1994,16 @@ }, { "name": "sebastian/global-state", - "version": "5.0.5", + "version": "5.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" + "reference": "bde739e7565280bda77be70044ac1047bc007e34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34", + "reference": "bde739e7565280bda77be70044ac1047bc007e34", "shasum": "" }, "require": { @@ -2045,7 +2046,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6" }, "funding": [ { @@ -2053,7 +2054,7 @@ "type": "github" } ], - "time": "2022-02-14T08:28:10+00:00" + "time": "2023-08-02T09:26:13+00:00" }, { "name": "sebastian/lines-of-code", @@ -2674,5 +2675,5 @@ "php": ">=8.0" }, "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/src/Database/Adapter.php b/src/Database/Adapter.php index c468a9666..b61e29192 100644 --- a/src/Database/Adapter.php +++ b/src/Database/Adapter.php @@ -659,7 +659,7 @@ abstract public function getMaxIndexLength(): int; * * @throws \Exception The provided timeout value must be greater than or equal to 0. */ - public static function setTimeoutForQueries(int $milliseconds): void + public static function setTimeout(int $milliseconds): void { if ($milliseconds <= 0) { throw new Exception('Timeout must be greater than 0'); @@ -673,7 +673,7 @@ public static function setTimeoutForQueries(int $milliseconds): void * @return void * */ - public static function clearTimeoutForQueries(): void + public static function clearTimeout(): void { self::$timeout = null; } diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index 8c1d90c9b..261aab657 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -1006,7 +1006,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25, "; if ($timeout || static::$timeout) { - $sql = $this->setTimeout($sql, $timeout ? $timeout : static::$timeout); + $sql = $this->setTimeoutForQuery($sql, $timeout ? $timeout : static::$timeout); } $stmt = $this->getPDO()->prepare($sql); @@ -1104,7 +1104,7 @@ public function count(string $collection, array $queries = [], ?int $max = null, ) table_count "; if ($timeout || self::$timeout) { - $sql = $this->setTimeout($sql, $timeout ? $timeout : self::$timeout); + $sql = $this->setTimeoutForQuery($sql, $timeout ? $timeout : self::$timeout); } $stmt = $this->getPDO()->prepare($sql); @@ -1160,7 +1160,7 @@ public function sum(string $collection, string $attribute, array $queries = [], ) table_count "; if ($timeout || self::$timeout) { - $sql = $this->setTimeout($sql, $timeout ? $timeout : self::$timeout); + $sql = $this->setTimeoutForQuery($sql, $timeout ? $timeout : self::$timeout); } $stmt = $this->getPDO()->prepare($sql); @@ -1377,7 +1377,7 @@ public function getSupportForTimeouts(): bool * @param int $milliseconds * @return string */ - protected function setTimeout(string $sql, int $milliseconds): string + protected function setTimeoutForQuery(string $sql, int $milliseconds): string { if (!$this->getSupportForTimeouts()) { return $sql; diff --git a/src/Database/Adapter/MySQL.php b/src/Database/Adapter/MySQL.php index 6bc4e9b0f..414a7ccbf 100644 --- a/src/Database/Adapter/MySQL.php +++ b/src/Database/Adapter/MySQL.php @@ -56,7 +56,7 @@ protected function getSQLIndex(string $collection, string $id, string $type, arr * @param int $milliseconds * @return string */ - protected function setTimeOut(string $sql, int $milliseconds): string + protected function setTimeoutForQuery(string $sql, int $milliseconds): string { return preg_replace('/SELECT/', "SELECT /*+ max_execution_time({$milliseconds}) */", $sql, 1); } diff --git a/src/Database/Adapter/Postgres.php b/src/Database/Adapter/Postgres.php index 15b578ec3..80527af3f 100644 --- a/src/Database/Adapter/Postgres.php +++ b/src/Database/Adapter/Postgres.php @@ -1016,7 +1016,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25, "; if ($timeout || self::$timeout) { - $sql = $this->setTimeout($sql, $timeout ? $timeout : self::$timeout); + $sql = $this->setTimeoutForQuery($sql, $timeout ? $timeout : self::$timeout); } $stmt = $this->getPDO()->prepare($sql); @@ -1116,7 +1116,7 @@ public function count(string $collection, array $queries = [], ?int $max = null, "; if ($timeout || self::$timeout) { - $sql = $this->setTimeout($sql, $timeout ? $timeout : self::$timeout); + $sql = $this->setTimeoutForQuery($sql, $timeout ? $timeout : self::$timeout); } $stmt = $this->getPDO()->prepare($sql); @@ -1175,7 +1175,7 @@ public function sum(string $collection, string $attribute, array $queries = [], "; if ($timeout || self::$timeout) { - $sql = $this->setTimeout($sql, $timeout ? $timeout : self::$timeout); + $sql = $this->setTimeoutForQuery($sql, $timeout ? $timeout : self::$timeout); } $stmt = $this->getPDO()->prepare($sql); @@ -1466,7 +1466,7 @@ public function getSupportForTimeouts(): bool * @param int $milliseconds * @return string */ - protected function setTimeout(string $sql, int $milliseconds): string + protected function setTimeoutForQuery(string $sql, int $milliseconds): string { return "SET statement_timeout = {$milliseconds};{$sql};SET statement_timeout = 0;"; } diff --git a/src/Database/Database.php b/src/Database/Database.php index 9c419c36b..6c97a0878 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -4219,14 +4219,14 @@ public function sum(string $collection, string $attribute, array $queries = [], return $sum; } - public function setTimeoutForQueries(int $milliseconds): void + public function setTimeout(int $milliseconds): void { - $this->adapter->setTimeoutForQueries($milliseconds); + $this->adapter->setTimeout($milliseconds); } - public function clearTimeoutForQueries(): void + public function clearTimeout(): void { - $this->adapter->clearTimeoutForQueries(); + $this->adapter->clearTimeout(); } /** * Add Attribute Filter diff --git a/tests/Database/Base.php b/tests/Database/Base.php index d9f61338d..a93c001b0 100644 --- a/tests/Database/Base.php +++ b/tests/Database/Base.php @@ -241,14 +241,14 @@ public function testQueryTimeoutUsingStaticTimeout(): void } $this->expectException(Timeout::class); - static::getDatabase()->setTimeoutForQueries(1); + static::getDatabase()->setTimeout(1); try { static::getDatabase()->find('global-timeouts', [ Query::notEqual('longtext', 'appwrite'), ]); } catch(Timeout $ex) { - static::getDatabase()->clearTimeoutForQueries(); + static::getDatabase()->clearTimeout(); static::getDatabase()->deleteCollection('global-timeouts'); throw $ex; }