Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 1 addition & 30 deletions src/Database/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
9 changes: 8 additions & 1 deletion src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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');
}
Expand All @@ -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;
}

Expand Down
Loading