From fd6739941733f2416e1394963d44974d4aa7846a Mon Sep 17 00:00:00 2001 From: Mateusz Uzdowski Date: Mon, 30 Mar 2015 11:29:33 +1300 Subject: [PATCH] Optimise diff generation. For 100 items, this change improves generation times on small diffs (100s of bytes) 6-fold. The improvement deteriorates to about 4-fold on diffs of 1kB. This includes the 25% improvement from the removal of unnecessary forTemplate calls - we pack the diffs into HTMLText and render them later from a template anyway. --- code/VersionFeed.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/code/VersionFeed.php b/code/VersionFeed.php index b8cb33d..995b1a1 100644 --- a/code/VersionFeed.php +++ b/code/VersionFeed.php @@ -71,24 +71,28 @@ class VersionFeed extends SiteTreeExtension { foreach ($versions as $version) { $changed = false; + // Check if we have something to compare with. if (isset($previous)) { - // We have something to compare with. - $diff = $this->owner->compareVersions($version->Version, $previous->Version); // Produce the diff fields for use in the template. if ($version->Title != $previous->Title) { + $diffTitle = Diff::compareHTML($version->Title, $previous->Title); + $version->DiffTitle = new HTMLText(); $version->DiffTitle->setValue( sprintf( - '
%s' . $diff->Title . '
', + '
%s ' . $diffTitle . '
', _t('RSSHistory.TITLECHANGED', 'Title has changed:') ) ); $changed = true; } + if ($version->Content != $previous->Content) { + $diffContent = Diff::compareHTML($version->Content, $previous->Content); + $version->DiffContent = new HTMLText(); - $version->DiffContent->setValue('
'.$diff->obj('Content')->forTemplate().'
'); + $version->DiffContent->setValue('
'.$diffContent.'
'); $changed = true; } @@ -112,7 +116,7 @@ class VersionFeed extends SiteTreeExtension { if ($previous && $versions->count()<$qLimit) { $first = clone($previous); $first->DiffContent = new HTMLText(); - $first->DiffContent->setValue('
' . $first->obj('Content')->forTemplate() . '
'); + $first->DiffContent->setValue('
' . $first->Content . '
'); // Copy the link so it can be cached by SS_Cache. $first->GeneratedLink = $first->AbsoluteLink(); $changeList->push($first);