Skip to content
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

WIP: FIX Filtering the version history by a specific date is now more performant in large datasets #197

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 13 additions & 22 deletions src/Versioned.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Extension;
use SilverStripe\Core\Resettable;
use SilverStripe\Dev\Deprecation;
Expand Down Expand Up @@ -629,33 +630,23 @@ protected function augmentSQLVersionedArchive(SQLSelect $query, DataQuery $dataQ
$stageColumn = $stage === static::LIVE
? 'WasPublished'
: 'WasDraft';
$stageCondition = "AND \"{$baseTable}_Versions\".\"{$stageColumn}\" = 1";
$stageCondition = "AND \"{$baseTable}_Versions_Latest\".\"{$stageColumn}\" = 1";
} else {
$stageCondition = '';
}

// Join on latest version filtered by date
$query->addInnerJoin(
<<<SQL
(
SELECT "{$baseTable}_Versions"."RecordID",
MAX("{$baseTable}_Versions"."Version") AS "LatestVersion"
FROM "{$baseTable}_Versions"
WHERE "{$baseTable}_Versions"."LastEdited" <= ?
// Filter by latest version (based on date)
$date = Convert::raw2sql($date);
$latestVersionSql = <<<SQL
(
SELECT MAX("{$baseTable}_Versions_Latest"."Version")
FROM "{$baseTable}_Versions" AS "{$baseTable}_Versions_Latest"
WHERE "{$baseTable}_Versions_Latest"."LastEdited" <= {$date}
AND "{$baseTable}_Versions_Latest"."RecordID" = "{$baseTable}_Versions"."RecordID"
{$stageCondition}
GROUP BY "{$baseTable}_Versions"."RecordID"
)
SQL
,
<<<SQL
"{$baseTable}_Versions_Latest"."RecordID" = "{$baseTable}_Versions"."RecordID"
AND "{$baseTable}_Versions_Latest"."LatestVersion" = "{$baseTable}_Versions"."Version"
SQL
,
"{$baseTable}_Versions_Latest",
20,
[$date]
);
)
SQL;
$query->addWhere(["\"{$baseTable}_Versions\".\"Version\"" => $latestVersionSql]);
}

/**
Expand Down