diff --git a/composer.json b/composer.json index 36c7700..68cc435 100644 --- a/composer.json +++ b/composer.json @@ -35,8 +35,7 @@ "phpunit/phpunit": "^11.0.6", "amphp/php-cs-fixer-config": "^2.0.1", "friendsofphp/php-cs-fixer": "^3.51", - "amphp/process": "^2.0", - "brianium/paratest": "^7.4" + "amphp/process": "^2.0" }, "scripts": { "cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php -d pcre.jit=0 vendor/bin/php-cs-fixer fix -v" diff --git a/src/Annotations/OrmMappedArray.php b/src/Annotations/OrmMappedArray.php index 6e81e50..13a5b5d 100644 --- a/src/Annotations/OrmMappedArray.php +++ b/src/Annotations/OrmMappedArray.php @@ -48,7 +48,7 @@ final class OrmMappedArray * * @var int<1, max>|null */ - public readonly ?int $optimizeIfWastedGtMb = null, + public readonly ?int $optimizeIfWastedMb = null, /** * Table name postfix, if null defaults to the property name. */ diff --git a/src/DbAutoProperties.php b/src/DbAutoProperties.php index 66d3a11..23536ad 100644 --- a/src/DbAutoProperties.php +++ b/src/DbAutoProperties.php @@ -56,12 +56,12 @@ trait DbAutoProperties )); } if ($settings instanceof Mysql) { - $optimize = $attr->optimizeIfWastedGtMb ?? $settings->optimizeIfWastedGtMb; + $optimize = $attr->optimizeIfWastedMb ?? $settings->optimizeIfWastedMb; - if ($optimize !== $settings->optimizeIfWastedGtMb) { + if ($optimize !== $settings->optimizeIfWastedMb) { $settings = new $settings(\array_merge( (array) $settings, - ['optimizeIfWastedGtMb' => $optimize] + ['optimizeIfWastedMb' => $optimize] )); } } diff --git a/src/Driver/DriverArray.php b/src/Driver/DriverArray.php index 39ba135..de3f0ce 100644 --- a/src/Driver/DriverArray.php +++ b/src/Driver/DriverArray.php @@ -73,7 +73,8 @@ abstract class DriverArray extends DbArray } else { $promises = []; foreach ($previous->getIterator() as $key => $value) { - $promises []= async($instance->set(...), $key, $value); + $promises []= async($previous->unset(...), $key) + ->map(static fn () => $instance->set($key, $value)); if (\count($promises) % 500 === 0) { await($promises); $promises = []; @@ -82,7 +83,6 @@ abstract class DriverArray extends DbArray if ($promises) { await($promises); } - $previous->clear(); } return $instance; diff --git a/src/Internal/Driver/MysqlArray.php b/src/Internal/Driver/MysqlArray.php index eae87bf..4179d68 100644 --- a/src/Internal/Driver/MysqlArray.php +++ b/src/Internal/Driver/MysqlArray.php @@ -164,7 +164,7 @@ final class MysqlArray extends SqlArray } } - if ($settings->optimizeIfWastedGtMb !== null) { + if ($settings->optimizeIfWastedMb !== null) { $database = $settings->config->getDatabase(); $result = $db->prepare("SELECT data_free FROM information_schema.tables WHERE table_schema=? AND table_name=?") ->execute([$database, $config->table]) @@ -172,7 +172,7 @@ final class MysqlArray extends SqlArray Assert::notNull($result); $result = $result['data_free'] ?? $result['DATA_FREE']; Assert::integer($result, "Could not optimize table!"); - if (($result >> 20) > $settings->optimizeIfWastedGtMb) { + if (($result >> 20) >= $settings->optimizeIfWastedMb) { $db->query("OPTIMIZE TABLE `{$config->table}`"); } } diff --git a/src/Internal/Driver/RedisArray.php b/src/Internal/Driver/RedisArray.php index 151b714..d37210a 100644 --- a/src/Internal/Driver/RedisArray.php +++ b/src/Internal/Driver/RedisArray.php @@ -85,30 +85,12 @@ final class RedisArray extends DriverArray $this->db = self::$connections[$dbKey]; } - protected function moveDataFromTableToTable(string $from, string $to): void - { - $from = "va:$from"; - $to = "va:$to"; - - $request = $this->db->scan($from.'*'); - - $lenK = \strlen($from); - foreach ($request as $oldKey) { - $newKey = $to.\substr($oldKey, $lenK); - $value = $this->db->get($oldKey); - if ($value !== null) { - $this->db->set($newKey, $value); - $this->db->delete($oldKey); - } - } - } - /** * Get redis key name. */ private function rKey(string $key): string { - return 'va:'.$this->config->table.':'.$key; + return $this->config->table.':'.$key; } /** @@ -116,7 +98,7 @@ final class RedisArray extends DriverArray */ private function itKey(): string { - return 'va:'.$this->config->table.'*'; + return $this->config->table.':*'; } public function set(string|int $key, mixed $value): void diff --git a/src/Settings/Mysql.php b/src/Settings/Mysql.php index 752dcad..659aa9f 100644 --- a/src/Settings/Mysql.php +++ b/src/Settings/Mysql.php @@ -50,9 +50,9 @@ final readonly class Mysql extends SqlSettings * * If null disables optimization. * - * @var int<1, max>|null $optimizeIfWastedGtMb + * @var int<1, max>|null $optimizeIfWastedMb */ - public ?int $optimizeIfWastedGtMb = null, + public ?int $optimizeIfWastedMb = null, ) { parent::__construct($config, $serializer, $cacheTtl, $maxConnections, $idleTimeout); } diff --git a/tests/OrmTest.php b/tests/OrmTest.php index 80a3b4f..919981a 100644 --- a/tests/OrmTest.php +++ b/tests/OrmTest.php @@ -333,7 +333,6 @@ final class OrmTest extends TestCase } $this->assertEquals(1, $cnt); - $field = new FieldConfig( $table.'_new', $settings, @@ -521,6 +520,12 @@ final class OrmTest extends TestCase $serializer, $ttl, )], + [$key++, new Mysql( + MysqlConfig::fromString('host=127.0.0.1:3306 user=root db=test'), + $serializer, + $ttl, + optimizeIfWastedMb: 0, + )], ]; } }