diff --git a/src/Abuse/Adapters/TimeLimit/Appwrite/TablesDB.php b/src/Abuse/Adapters/TimeLimit/Appwrite/TablesDB.php index 89db961696..94ad05ad61 100644 --- a/src/Abuse/Adapters/TimeLimit/Appwrite/TablesDB.php +++ b/src/Abuse/Adapters/TimeLimit/Appwrite/TablesDB.php @@ -260,49 +260,34 @@ class TablesDB extends TimeLimit */ protected function set(string $key, int $timestamp, int $value): void { - if (0 == $this->limit) { // No limit no point for counting - return; - } - $timestamp = $this->toDateTime($timestamp); - $response = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [ - Query::equal('key', [$key]), - Query::equal('time', [$timestamp]), - ]); - $rows = $response['rows']; - $data = $rows[0] ?? null; + $data = [ + 'key' => $key, + 'time' => $timestamp, + 'count' => $value, + ]; - if (\is_null($data)) { - $data = [ - 'key' => $key, - 'time' => $timestamp, - 'count' => $value, - ]; + try { + $this->tablesDB->createRow($this->databaseId, self::TABLE_ID, ID::unique(), $data); + } catch (AppwriteException $err) { + if ($err->getType() !== 'row_already_exists') { + throw $err; + } - try { - $this->tablesDB->createRow($this->databaseId, self::TABLE_ID, ID::unique(), $data); - } catch (AppwriteException $err) { - if ($err->getType() !== 'row_already_exists') { - throw $err; - } + $response = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [ + Query::equal('key', [$key]), + Query::equal('time', [$timestamp]), + ]); + $rows = $response['rows']; - $response = $this->tablesDB->listRows($this->databaseId, self::TABLE_ID, [ - Query::equal('key', [$key]), - Query::equal('time', [$timestamp]), - ]); - $rows = $response['rows']; + $data = $rows[0] ?? null; - $data = $rows[0] ?? null; - - if (!is_null($data)) { - $this->tablesDB->updateRow($this->databaseId, self::TABLE_ID, $data['$id'], ['count' => $value]); - } else { - throw new \Exception('Unable to find abuse tracking row after race condition handling'); - } + if (!is_null($data)) { + $this->tablesDB->updateRow($this->databaseId, self::TABLE_ID, $data['$id'], ['count' => $value]); + } else { + throw new \Exception('Unable to find abuse tracking row after race condition handling'); } - } else { - $this->tablesDB->updateRow($this->databaseId, self::TABLE_ID, $data['$id'], ['count' => $value]); } $this->count = $value; diff --git a/src/Abuse/Adapters/TimeLimit/Database.php b/src/Abuse/Adapters/TimeLimit/Database.php index 2e7648830a..9fa8a4c478 100644 --- a/src/Abuse/Adapters/TimeLimit/Database.php +++ b/src/Abuse/Adapters/TimeLimit/Database.php @@ -225,10 +225,6 @@ class Database extends TimeLimit */ protected function set(string $key, int $timestamp, int $value): void { - if (0 == $this->limit) { // No limit no point for counting - return; - } - $timestamp = $this->toDateTime($timestamp); Authorization::skip(function () use ($timestamp, $key, $value) { $data = $this->db->findOne(self::COLLECTION, [ diff --git a/src/Abuse/Adapters/TimeLimit/Redis.php b/src/Abuse/Adapters/TimeLimit/Redis.php index 8db3e29950..2ffb02090b 100644 --- a/src/Abuse/Adapters/TimeLimit/Redis.php +++ b/src/Abuse/Adapters/TimeLimit/Redis.php @@ -87,10 +87,6 @@ class Redis extends TimeLimit */ protected function set(string $key, int $timestamp, int $value): void { - if (0 == $this->limit) { // No limit no point for counting - return; - } - $key = self::NAMESPACE . '__' . $key . '__' . $timestamp; $this->redis->multi() ->set($key, (string)$value) diff --git a/src/Abuse/Adapters/TimeLimit/RedisCluster.php b/src/Abuse/Adapters/TimeLimit/RedisCluster.php index abb6379030..12ec73e06b 100644 --- a/src/Abuse/Adapters/TimeLimit/RedisCluster.php +++ b/src/Abuse/Adapters/TimeLimit/RedisCluster.php @@ -89,10 +89,6 @@ class RedisCluster extends TimeLimit */ protected function set(string $key, int $timestamp, int $value): void { - if (0 == $this->limit) { // No limit no point for counting - return; - } - $key = self::NAMESPACE . '__' . $key . '__' . $timestamp; $this->redis->multi();