mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Remove persistModel.
The benefits of persistModel are no longer needed. Because of lazy model associations, the performance benefits persistModel are no longer realized. Fixes #1782
This commit is contained in:
parent
1c7d54eacc
commit
ed8ccc2903
2 changed files with 7 additions and 61 deletions
|
@ -236,15 +236,6 @@ class Controller extends Object {
|
|||
*/
|
||||
public $cacheAction = false;
|
||||
|
||||
/**
|
||||
* Used to create cached instances of models a controller uses.
|
||||
* When set to true, all models related to the controller will be cached.
|
||||
* This can increase performance in many cases.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $persistModel = false;
|
||||
|
||||
/**
|
||||
* Holds all params passed and named.
|
||||
*
|
||||
|
@ -593,8 +584,6 @@ class Controller extends Object {
|
|||
|
||||
/**
|
||||
* Loads and instantiates models required by this controller.
|
||||
* If Controller::$persistModel; is true, controller will cache model instances on first request,
|
||||
* additional request will used cached models.
|
||||
* If the model is non existent, it will throw a missing database table error, as Cake generates
|
||||
* dynamic models for the time being.
|
||||
*
|
||||
|
@ -607,36 +596,16 @@ class Controller extends Object {
|
|||
if ($modelClass === null) {
|
||||
$modelClass = $this->modelClass;
|
||||
}
|
||||
$cached = false;
|
||||
$object = null;
|
||||
list($plugin, $modelClass) = pluginSplit($modelClass, true);
|
||||
|
||||
if ($this->persistModel === true) {
|
||||
$cached = $this->_persist($modelClass, null, $object);
|
||||
$this->modelNames[] = $modelClass;
|
||||
|
||||
$this->{$modelClass} = ClassRegistry::init(array(
|
||||
'class' => $plugin . $modelClass, 'alias' => $modelClass, 'id' => $id
|
||||
));
|
||||
if (!$this->{$modelClass}) {
|
||||
throw new MissingModelException($modelClass);
|
||||
}
|
||||
|
||||
if (($cached === false)) {
|
||||
$this->modelNames[] = $modelClass;
|
||||
|
||||
$this->{$modelClass} = ClassRegistry::init(array(
|
||||
'class' => $plugin . $modelClass, 'alias' => $modelClass, 'id' => $id
|
||||
));
|
||||
|
||||
if (!$this->{$modelClass}) {
|
||||
throw new MissingModelException($modelClass);
|
||||
}
|
||||
|
||||
if ($this->persistModel === true) {
|
||||
$this->_persist($modelClass, true, $this->{$modelClass});
|
||||
$registry = ClassRegistry::getInstance();
|
||||
$this->_persist($modelClass . 'registry', true, $registry->__objects, 'registry');
|
||||
}
|
||||
} else {
|
||||
$this->_persist($modelClass . 'registry', true, $object, 'registry');
|
||||
$this->_persist($modelClass, true, $object);
|
||||
$this->modelNames[] = $modelClass;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -513,29 +513,6 @@ class ControllerTest extends CakeTestCase {
|
|||
unset($Controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* testPersistent method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function testPersistent() {
|
||||
$this->markTestIncomplete('persistModel is totally broken right now.');
|
||||
|
||||
Configure::write('Cache.disable', false);
|
||||
$Controller = new Controller();
|
||||
$Controller->modelClass = 'ControllerPost';
|
||||
$Controller->persistModel = true;
|
||||
$Controller->constructClasses();
|
||||
$this->assertTrue(file_exists(CACHE . 'persistent' . DS .'controllerpost.php'));
|
||||
$this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
|
||||
@unlink(CACHE . 'persistent' . DS . 'controllerpost.php');
|
||||
@unlink(CACHE . 'persistent' . DS . 'controllerpostregistry.php');
|
||||
|
||||
unset($Controller);
|
||||
Configure::write('Cache.disable', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* testFlash method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue