-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: Performance optimisation for draft pages in treeview #181
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d597166
FIX: Performance optimisation for draft pages in treeview
02a201e
Improve unit test converage for prepopulate_versionnumber_cache.
840f008
Use Data provider to test version number caching
651da34
Switch back to using VersionedTest\TestObject
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
namespace SilverStripe\Versioned\Tests; | ||
|
||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\Versioned\Versioned; | ||
use SilverStripe\Versioned\Tests\VersionedTest\TestObject; | ||
|
||
/** | ||
* @internal Only test the right values are returned, not that the cache is actually used. | ||
*/ | ||
class VersionedNumberCacheTest extends SapphireTest | ||
{ | ||
|
||
public static $extra_dataobjects = [ | ||
VersionedTest\TestObject::class | ||
]; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private static $publishedID; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private static $draftOnlyID; | ||
|
||
private static $expectedVersions = [ ]; | ||
|
||
|
||
public static function setUpBeforeClass() | ||
{ | ||
parent::setUpBeforeClass(); | ||
|
||
// Initialise our dummy object | ||
$obj = TestObject::create(['Title' => 'Initial version']); | ||
$obj->write(); | ||
self::$publishedID = $obj->ID; | ||
|
||
// Create our live version | ||
$obj->Title = 'This will be our live version'; | ||
$obj->write(); | ||
$obj->publishSingle(); | ||
$liveVersion = $obj->Version; | ||
|
||
// Create our draft version | ||
$obj->Title = 'This will be our draft version'; | ||
$obj->write(); | ||
$draftVersion = $obj->Version; | ||
|
||
// This object won't ne publish | ||
$draftOnly = TestObject::create(['Title' => 'Draft Only object']); | ||
$draftOnly->write(); | ||
self::$draftOnlyID = $draftOnly->ID; | ||
|
||
self::$expectedVersions = [ | ||
'liveVersion' => $liveVersion, | ||
'draftVersion' => $draftVersion, | ||
'null' => null | ||
]; | ||
} | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
TestObject::singleton()->flushCache(); | ||
} | ||
|
||
public function cacheDataProvider() | ||
{ | ||
return [ | ||
[Versioned::DRAFT, 'publishedID', false, 'draftVersion'], | ||
[Versioned::DRAFT, 'publishedID', true, 'draftVersion'], | ||
[Versioned::LIVE, 'publishedID', false, 'liveVersion'], | ||
[Versioned::LIVE, 'publishedID', true, 'liveVersion'], | ||
[Versioned::LIVE, 'draftOnlyID', false, 'null'], | ||
[Versioned::LIVE, 'draftOnlyID', true, 'null'], | ||
]; | ||
} | ||
|
||
|
||
/** | ||
* @dataProvider cacheDataProvider | ||
*/ | ||
public function testVersionNumberCache($stage, $ID, $cache, $expected) | ||
{ | ||
$actual = Versioned::get_versionnumber_by_stage(TestObject::class, $stage, self::${$ID}, $cache); | ||
$this->assertEquals(self::$expectedVersions[$expected], $actual); | ||
|
||
if ($cache) { | ||
// When cahing is eanbled, try re-accessing version number to make sure the cache returns the same value | ||
$actual = Versioned::get_versionnumber_by_stage(TestObject::class, $stage, self::${$ID}, $cache); | ||
$this->assertEquals(self::$expectedVersions[$expected], $actual); | ||
} | ||
} | ||
|
||
/** | ||
* @dataProvider cacheDataProvider | ||
*/ | ||
public function testPrepopulatedVersionNumberCache($stage, $ID, $cache, $expected) | ||
{ | ||
Versioned::prepopulate_versionnumber_cache(TestObject::class, $stage); | ||
$actual = Versioned::get_versionnumber_by_stage(TestObject::class, $stage, self::${$ID}, $cache); | ||
$this->assertEquals(self::$expectedVersions[$expected], $actual); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a sidenote, I find that data providers should only be used if the data within them is pretty self explanatory. If you find yourself going back and forth between the provider and the implementation (like I'm doing in this case), it's not helping readability. And in unit tests, I think readability overrules DRY principles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@robbieaverill @chillu You guys are tough customers to please 😉
I'll keep it in mind for the next time.