From c36a0b15fb41357566aa140d893da4d5b90aca8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 7 May 2025 19:16:58 +0000 Subject: [PATCH 1/2] Disable transactions --- src/Database/Adapter.php | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/src/Database/Adapter.php b/src/Database/Adapter.php index 9b25dae55..ce55a62c7 100644 --- a/src/Database/Adapter.php +++ b/src/Database/Adapter.php @@ -371,36 +371,7 @@ public function inTransaction(): bool */ public function withTransaction(callable $callback): mixed { - for ($attempts = 0; $attempts < 3; $attempts++) { - try { - $this->startTransaction(); - $result = $callback(); - $this->commitTransaction(); - return $result; - } catch (\Throwable $action) { - try { - $this->rollbackTransaction(); - } catch (\Throwable $rollback) { - if ($attempts < 2) { - \usleep(5000); // 5ms - continue; - } - - $this->inTransaction = 0; - throw $rollback; - } - - if ($attempts < 2) { - \usleep(5000); // 5ms - continue; - } - - $this->inTransaction = 0; - throw $action; - } - } - - throw new TransactionException('Failed to execute transaction'); + return $callback(); // Skip transaction to benchmark } /** From 24ce68756423ed767c17ecf5d928e9115a1536da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 7 May 2025 19:41:25 +0000 Subject: [PATCH 2/2] Add logging --- composer.lock | 4 ++-- src/Database/Database.php | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/composer.lock b/composer.lock index 3abe843d8..bb95433b0 100644 --- a/composer.lock +++ b/composer.lock @@ -4131,7 +4131,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -4139,6 +4139,6 @@ "ext-pdo": "*", "ext-mbstring": "*" }, - "platform-dev": [], + "platform-dev": {}, "plugin-api-version": "2.6.0" } diff --git a/src/Database/Database.php b/src/Database/Database.php index 43f4cd923..1ac8c6ee8 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -1499,6 +1499,7 @@ public function deleteCollection(string $id): bool */ public function createAttribute(string $collection, string $id, string $type, int $size, bool $required, mixed $default = null, bool $signed = true, bool $array = false, ?string $format = null, array $formatOptions = [], array $filters = []): bool { + $tt1 = \microtime(true); $collection = $this->silent(fn () => $this->getCollection($collection)); if ($collection->isEmpty()) { @@ -1577,8 +1578,11 @@ public function createAttribute(string $collection, string $id, string $type, in } try { + $t1 = \microtime(true); $created = $this->adapter->createAttribute($collection->getId(), $id, $type, $size, $signed, $array); - + $t2 = \microtime(true); + $diff = $t2 - $t1; + \var_dump("Create (" . $diff . "s): " . $collection->getId() . " - " . $id); if (!$created) { throw new DatabaseException('Failed to create attribute'); } @@ -1598,6 +1602,9 @@ public function createAttribute(string $collection, string $id, string $type, in $this->trigger(self::EVENT_ATTRIBUTE_CREATE, $attribute); + $tt2 = microtime(true); + $diff2 = $tt2 - $tt1; + \var_dump("Total (" . $diff2 . "s): " . $collection->getId() . " - " . $id); return true; }