diff --git a/ActiveQuery.php b/ActiveQuery.php index 2e15fde..7a765e9 100644 --- a/ActiveQuery.php +++ b/ActiveQuery.php @@ -339,7 +339,9 @@ class ActiveQuery extends Component implements ISqlBuilder { $sql = $this->builder->delete(); if ($getSql === FALSE) { - return (bool)$this->execute($sql, $this->attributes)->delete(); + $result = (bool)$this->execute($sql, $this->attributes)->delete(); + $this->modelClass->optimize(); + return $result; } return $sql; } diff --git a/Base/Model.php b/Base/Model.php index c375983..d99ec79 100644 --- a/Base/Model.php +++ b/Base/Model.php @@ -265,6 +265,16 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T } + /** + * @return mixed + * @throws Exception + */ + public function optimize(): mixed + { + return static::query()->execute('OPTIMIZE TABLE ' . $this->getTable())->exec(); + } + + /** * @return static */ diff --git a/Command.php b/Command.php index 5d9f21c..61a418b 100644 --- a/Command.php +++ b/Command.php @@ -108,10 +108,10 @@ class Command extends Component } /** - * @return bool|array|null + * @return mixed * @throws Exception */ - public function fetchColumn(): null|bool|array + public function fetchColumn(): mixed { try { return $this->prepare()->fetchColumn(PDO::FETCH_ASSOC); diff --git a/Model.php b/Model.php index 805fb7b..bbb4fd4 100644 --- a/Model.php +++ b/Model.php @@ -197,6 +197,7 @@ class Model extends Base\Model } else { $result = static::deleteByCondition($this->_attributes); } + $this->optimize(); return $this->afterDelete($result); } return false; diff --git a/ModelInterface.php b/ModelInterface.php index 671d2f4..3a94a3d 100644 --- a/ModelInterface.php +++ b/ModelInterface.php @@ -25,6 +25,12 @@ interface ModelInterface public static function findOne(array|string|int $param, $db = NULL): ?static; + /** + * @return mixed + */ + public function optimize(): mixed; + + /** * @param int $param * @param null $db