Merge pull request #2203 from camspiers/config-memory

Improve memory performance when generating config static and class caches
This commit is contained in:
Ingo Schommer 2013-07-08 06:35:31 -07:00
commit 3bfb82d25f
4 changed files with 32 additions and 15 deletions

View File

@ -273,6 +273,15 @@ class SS_ClassManifest {
return $modules;
}
/**
* Used to set up files that we want to exclude from parsing for performance reasons.
*/
protected function setDefaults()
{
$this->classes['sstemplateparser'] = FRAMEWORK_PATH.'/view/SSTemplateParser.php';
$this->classes['sstemplateparseexception'] = FRAMEWORK_PATH.'/view/SSTemplateParser.php';
}
/**
* Completely regenerates the manifest file.
*
@ -289,10 +298,12 @@ class SS_ClassManifest {
$this->$reset = array();
}
$this->setDefaults();
$finder = new ManifestFileFinder();
$finder->setOptions(array(
'name_regex' => '/^(_config.php|[^_].*\.php)$/',
'ignore_files' => array('index.php', 'main.php', 'cli-script.php'),
'ignore_files' => array('index.php', 'main.php', 'cli-script.php', 'SSTemplateParser.php'),
'ignore_tests' => !$this->tests,
'file_callback' => array($this, 'handleFile'),
'dir_callback' => array($this, 'handleDir')

View File

@ -100,7 +100,7 @@ class SS_ConfigStaticManifest {
$finder = new ManifestFileFinder();
$finder->setOptions(array(
'name_regex' => '/^([^_].*\.php)$/',
'ignore_files' => array('index.php', 'main.php', 'cli-script.php'),
'ignore_files' => array('index.php', 'main.php', 'cli-script.php', 'SSTemplateParser.php'),
'ignore_tests' => !$this->tests,
'file_callback' => array($this, 'handleFile')
));

View File

@ -36,17 +36,20 @@ class ClassManifestTest extends SapphireTest {
public function testGetClasses() {
$expect = array(
'classa' => "{$this->base}/module/classes/ClassA.php",
'classb' => "{$this->base}/module/classes/ClassB.php",
'classc' => "{$this->base}/module/classes/ClassC.php",
'classd' => "{$this->base}/module/classes/ClassD.php"
'classb' => "{$this->base}/module/classes/ClassB.php",
'classa' => "{$this->base}/module/classes/ClassA.php",
'classb' => "{$this->base}/module/classes/ClassB.php",
'classc' => "{$this->base}/module/classes/ClassC.php",
'classd' => "{$this->base}/module/classes/ClassD.php",
'sstemplateparser' => FRAMEWORK_PATH."/view/SSTemplateParser.php",
'sstemplateparseexception' => FRAMEWORK_PATH."/view/SSTemplateParser.php"
);
$this->assertEquals($expect, $this->manifest->getClasses());
}
public function testGetClassNames() {
$this->assertEquals(
array('classa', 'classb', 'classc', 'classd'),
array('sstemplateparser', 'sstemplateparseexception', 'classa', 'classb', 'classc', 'classd'),
$this->manifest->getClassNames());
}

View File

@ -12,7 +12,7 @@ class NamespacedClassManifestTest extends SapphireTest {
public function setUp() {
parent::setUp();
$this->base = dirname(__FILE__) . '/fixtures/namespaced_classmanifest';
$this->manifest = new SS_ClassManifest($this->base, false, true, false);
}
@ -41,17 +41,20 @@ class NamespacedClassManifestTest extends SapphireTest {
'silverstripe\test\classe' => "{$this->base}/module/classes/ClassE.php",
'silverstripe\test\classf' => "{$this->base}/module/classes/ClassF.php",
'silverstripe\test\classg' => "{$this->base}/module/classes/ClassG.php",
'silverstripe\test\classh' => "{$this->base}/module/classes/ClassH.php"
'silverstripe\test\classh' => "{$this->base}/module/classes/ClassH.php",
'sstemplateparser' => FRAMEWORK_PATH."/view/SSTemplateParser.php",
'sstemplateparseexception' => FRAMEWORK_PATH."/view/SSTemplateParser.php"
);
$this->assertEquals($expect, $this->manifest->getClasses());
}
public function testGetClassNames() {
$this->assertEquals(
array('silverstripe\test\classa', 'silverstripe\test\classb', 'silverstripe\test\classc',
'silverstripe\test\classd', 'silverstripe\test\classe', 'silverstripe\test\classf',
'silverstripe\test\classg', 'silverstripe\test\classh'),
array('sstemplateparser', 'sstemplateparseexception', 'silverstripe\test\classa',
'silverstripe\test\classb', 'silverstripe\test\classc', 'silverstripe\test\classd',
'silverstripe\test\classe', 'silverstripe\test\classf', 'silverstripe\test\classg',
'silverstripe\test\classh'),
$this->manifest->getClassNames());
}
@ -59,7 +62,7 @@ class NamespacedClassManifestTest extends SapphireTest {
$expect = array(
'silverstripe\test\classa' => array('silverstripe\test\ClassB', 'silverstripe\test\ClassH'),
);
$this->assertEquals($expect, $this->manifest->getDescendants());
}
@ -109,7 +112,7 @@ class NamespacedClassManifestTest extends SapphireTest {
$expect = array("{$this->base}/module/_config.php");
$this->assertEquals($expect, $this->manifest->getConfigs());
}
public function testGetModules() {
$expect = array(
"module" => "{$this->base}/module",