You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
642 B
PHP
23 lines
642 B
PHP
<?php
|
|
|
|
namespace App\Services\Cloud;
|
|
|
|
use App\Models\CloudTrafficPool;
|
|
use Closure;
|
|
|
|
final class CloudTrafficConsistentRead
|
|
{
|
|
/** Use one InnoDB read view across all projections, without blocking accounting writers. */
|
|
public static function run(Closure $read): mixed
|
|
{
|
|
$db = (new CloudTrafficPool())->getConnection();
|
|
if ($db->transactionLevel() > 0) {
|
|
return $read();
|
|
}
|
|
if (in_array($db->getDriverName(), ['mysql', 'mariadb'], true)) {
|
|
$db->statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ ONLY');
|
|
}
|
|
return $db->transaction($read);
|
|
}
|
|
}
|