mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Remove limit check from set() methods and simplify TablesDB logic
Co-authored-by: Meldiron <19310830+Meldiron@users.noreply.github.com>
This commit is contained in:
1 parent
f9ed0685c9
commit
c5bfa4d6cd
4 files changed
+21
-48
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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, [
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user