mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
fix: codeql
This commit is contained in:
1 parent
aa15eda877
commit
76fc3da33b
5 files changed
+41
-34
No files matched your search
Generated
+5
-5
@@ -3040,16 +3040,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpstan/phpstan",
|
||||
"version": "1.12.12",
|
||||
"version": "1.12.13",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpstan/phpstan.git",
|
||||
"reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0"
|
||||
"reference": "9b469068840cfa031e1deaf2fa1886d00e20680f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0",
|
||||
"reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0",
|
||||
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/9b469068840cfa031e1deaf2fa1886d00e20680f",
|
||||
"reference": "9b469068840cfa031e1deaf2fa1886d00e20680f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -3094,7 +3094,7 @@
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2024-11-28T22:13:23+00:00"
|
||||
"time": "2024-12-17T17:00:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/php-code-coverage",
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Utopia\Abuse\Adapters\TimeLimit;
|
||||
|
||||
use Redis as Client;
|
||||
use Utopia\Abuse\Adapters\TimeLimit;
|
||||
|
||||
class Redis extends TimeLimit
|
||||
@@ -10,11 +9,11 @@ class Redis extends TimeLimit
|
||||
public const NAMESPACE = 'abuse';
|
||||
|
||||
/**
|
||||
* @var Client
|
||||
* @var \Redis
|
||||
*/
|
||||
protected Client $redis;
|
||||
protected \Redis $redis;
|
||||
|
||||
public function __construct(string $key, int $limit, int $seconds, Client $redis)
|
||||
public function __construct(string $key, int $limit, int $seconds, \Redis $redis)
|
||||
{
|
||||
$this->redis = $redis;
|
||||
$this->key = $key;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Utopia\Abuse\Adapters\TimeLimit;
|
||||
|
||||
use RedisCluster as Client;
|
||||
use Utopia\Abuse\Adapters\TimeLimit;
|
||||
|
||||
class RedisCluster extends TimeLimit
|
||||
@@ -10,11 +9,11 @@ class RedisCluster extends TimeLimit
|
||||
public const NAMESPACE = 'abuse';
|
||||
|
||||
/**
|
||||
* @var Client
|
||||
* @var \RedisCluster
|
||||
*/
|
||||
protected Client $redis;
|
||||
protected \RedisCluster $redis;
|
||||
|
||||
public function __construct(string $key, int $limit, int $seconds, Client $redis)
|
||||
public function __construct(string $key, int $limit, int $seconds, \RedisCluster $redis)
|
||||
{
|
||||
$this->redis = $redis;
|
||||
$this->key = $key;
|
||||
@@ -23,8 +22,8 @@ class RedisCluster extends TimeLimit
|
||||
$this->limit = $limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
/**
|
||||
* Get count for a key at specific datetime
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $datetime
|
||||
@@ -40,9 +39,9 @@ class RedisCluster extends TimeLimit
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
/** @var string $count */
|
||||
/** @var string|false $count */
|
||||
$count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $datetime);
|
||||
if (!$count) {
|
||||
if ($count === false) {
|
||||
$this->count = 0;
|
||||
} else {
|
||||
$this->count = intval($count);
|
||||
@@ -52,10 +51,11 @@ class RedisCluster extends TimeLimit
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $datetime
|
||||
* @return void
|
||||
* Record a hit for a key at specific datetime
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $datetime
|
||||
* @return void
|
||||
*/
|
||||
protected function hit(string $key, string $datetime): void
|
||||
{
|
||||
@@ -63,9 +63,9 @@ class RedisCluster extends TimeLimit
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var string $count */
|
||||
/** @var string|false $count */
|
||||
$count = $this->redis->get(self::NAMESPACE . '__'. $key .'__'. $datetime);
|
||||
if (!$count) {
|
||||
if ($count === false) {
|
||||
$this->count = 0;
|
||||
} else {
|
||||
$this->count = intval($count);
|
||||
@@ -80,16 +80,15 @@ class RedisCluster extends TimeLimit
|
||||
*
|
||||
* Return logs with an offset and limit
|
||||
*
|
||||
* @param int $offset
|
||||
* @param int|null $limit
|
||||
* @param int|null $offset
|
||||
* @param int|null $limit
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getLogs(int $offset = 0, ?int $limit = 25): array
|
||||
public function getLogs(?int $offset = 0, ?int $limit = 25): array
|
||||
{
|
||||
// TODO limit potential is SCAN but needs cursor no offset
|
||||
$cursor = null;
|
||||
$keys = $this->scan($cursor, self::NAMESPACE . '__*', $limit);
|
||||
if (!$keys) {
|
||||
$keys = $this->scan(self::NAMESPACE . '__*', $offset, $limit);
|
||||
if ($keys === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -103,14 +102,14 @@ class RedisCluster extends TimeLimit
|
||||
/**
|
||||
* Delete all logs older than $datetime
|
||||
*
|
||||
* @param string $datetime
|
||||
* @param string $datetime
|
||||
* @return bool
|
||||
*/
|
||||
public function cleanup(string $datetime): bool
|
||||
{
|
||||
$iterator = null;
|
||||
$keys = $this->scan($iterator, self::NAMESPACE . '__*__*', 1000);
|
||||
$keys = $this->scan(self::NAMESPACE . '__*__*');
|
||||
$keys = $this->filterKeys($keys ? $keys : [], (int) $datetime);
|
||||
/** @phpstan-ignore-next-line */
|
||||
$this->redis->del($keys);
|
||||
return true;
|
||||
}
|
||||
@@ -135,12 +134,21 @@ class RedisCluster extends TimeLimit
|
||||
return $filteredKeys;
|
||||
}
|
||||
|
||||
protected function scan(&$testing, string $pattern, int $count): array|bool
|
||||
/**
|
||||
* Scan keys across all masters in the Redis cluster
|
||||
*
|
||||
* @param string $pattern Pattern to match keys
|
||||
* @param int|null $cursor Reference to the cursor for scanning
|
||||
* @param int|null $count Number of keys to return per iteration
|
||||
* @return array<string>|false
|
||||
*/
|
||||
protected function scan(string $pattern, ?int &$cursor = null, ?int $count = 1000): array|false
|
||||
{
|
||||
$matches = [];
|
||||
foreach ($this->redis->_masters() as $master) {
|
||||
$cursor = null;
|
||||
do {
|
||||
/** @phpstan-ignore-next-line */
|
||||
$keys = $this->redis->scan($cursor, $master, $pattern, $count);
|
||||
if ($keys !== false) {
|
||||
$matches = array_merge($matches, $keys);
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Abuse\Bench\Database;
|
||||
|
||||
use PDO;
|
||||
use Utopia\Abuse\Abuse;
|
||||
use Utopia\Abuse\Adapters\Database\TimeLimit;
|
||||
use Utopia\Abuse\Adapters\TimeLimit\Database as TimeLimit;
|
||||
use Utopia\Cache\Adapter\None as NoCache;
|
||||
use Utopia\Cache\Cache;
|
||||
use Utopia\Database\Adapter\MariaDB;
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Abuse\Bench\Redis;
|
||||
|
||||
use Redis as Client;
|
||||
use Utopia\Abuse\Abuse;
|
||||
use Utopia\Abuse\Adapters\Redis\TimeLimit;
|
||||
use Utopia\Abuse\Adapters\TimeLimit\Redis as TimeLimit;
|
||||
use Utopia\Tests\Bench\Base;
|
||||
|
||||
final class TimeLimitBench extends Base
|
||||
|
||||
Reference in new issue
Block a user