Skip to content

Commit

Permalink
Merge pull request #303 from utopia-php/chore-rename-setTimeout-funct…
Browse files Browse the repository at this point in the history
…ions

rename setTimeout methods
  • Loading branch information
abnegate authored Aug 9, 2023
2 parents fb7435a + 3e2c4b9 commit 8eab2af
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 56 deletions.
79 changes: 40 additions & 39 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Adapter/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Database/Adapter/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;";
}
Expand Down
8 changes: 4 additions & 4 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -4241,14 +4241,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
Expand Down
4 changes: 2 additions & 2 deletions tests/Database/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8eab2af

Please sign in to comment.