diff --git a/src/Abuse/Adapters/TimeLimit/Appwrite/TablesDB.php b/src/Abuse/Adapters/TimeLimit/Appwrite/TablesDB.php index be0fa12e6c..94ad05ad61 100644 --- a/src/Abuse/Adapters/TimeLimit/Appwrite/TablesDB.php +++ b/src/Abuse/Adapters/TimeLimit/Appwrite/TablesDB.php @@ -262,43 +262,32 @@ class TablesDB extends TimeLimit { $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 a2eb69726b..9fa8a4c478 100644 --- a/src/Abuse/Adapters/TimeLimit/Database.php +++ b/src/Abuse/Adapters/TimeLimit/Database.php @@ -225,7 +225,6 @@ class Database extends TimeLimit */ protected function set(string $key, int $timestamp, int $value): void { - $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 e626573568..2ffb02090b 100644 --- a/src/Abuse/Adapters/TimeLimit/Redis.php +++ b/src/Abuse/Adapters/TimeLimit/Redis.php @@ -87,7 +87,6 @@ class Redis extends TimeLimit */ protected function set(string $key, int $timestamp, int $value): void { - $key = self::NAMESPACE . '__' . $key . '__' . $timestamp; $this->redis->multi() ->set($key, (string)$value)