This commit is contained in:
2021-02-23 19:27:28 +08:00
parent 074762cdae
commit 38eb573945
5 changed files with 28 additions and 36 deletions
-9
View File
@@ -46,15 +46,6 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
} }
/**
* recover class by clone
*/
public function __clone()
{
$this->clean();
}
/** /**
* Collection constructor. * Collection constructor.
* *
-9
View File
@@ -97,15 +97,6 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
} }
/**
* recover class by clone
*/
public function __clone()
{
$this->clean();
}
/** /**
* @throws Exception * @throws Exception
*/ */
-9
View File
@@ -33,15 +33,6 @@ class CollectionIterator extends \ArrayIterator
} }
/**
* recover class by clone
*/
public function __clone()
{
$this->clean();
}
/** /**
* CollectionIterator constructor. * CollectionIterator constructor.
* @param $model * @param $model
-8
View File
@@ -171,14 +171,6 @@ class Event extends BaseObject
} }
/**
* recover class by clone
*/
public function __clone()
{
$this->clean();
}
/** /**
* @param $name * @param $name
* @param array $params * @param array $params
+28 -1
View File
@@ -18,13 +18,20 @@ use Snowflake\Snowflake;
class ObjectPool extends \Snowflake\Abstracts\Pool class ObjectPool extends \Snowflake\Abstracts\Pool
{ {
private array $_waitRecover = [];
/** /**
* set pool max length * set pool max length
* @throws ComponentException
* @throws Exception
*/ */
public function init() public function init()
{ {
$this->max = 100; $this->max = 100;
$event = Snowflake::app()->getEvent();
$event->on(Event::EVENT_AFTER_REQUEST, [$this, 'destruct']);
} }
@@ -62,7 +69,27 @@ class ObjectPool extends \Snowflake\Abstracts\Pool
*/ */
public function release(string $name, mixed $object) public function release(string $name, mixed $object)
{ {
$this->push($name, clone $object); $this->_waitRecover[$name][] = $object;
}
public function destruct()
{
if (empty($this->_waitRecover)) {
return;
}
foreach ($this->_waitRecover as $name => $value) {
if (empty($value)) {
continue;
}
foreach ($value as $object) {
if (method_exists($object, 'clean')) {
$object->clean();
}
$this->push($name, $object);
}
}
$this->_waitRecover = [];
} }
} }