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

Optimize the reviseTable() method (see #438) #487

merged 2 commits into from May 14, 2019


None yet
3 participants
Copy link

commented May 13, 2019

This PR fixes #438 by optimizing the SQL queries to purge orphan child records.

@leofeyer leofeyer self-assigned this May 13, 2019

@leofeyer leofeyer added the defect label May 13, 2019

@leofeyer leofeyer added this to the 4.4.40 milestone May 13, 2019

@leofeyer leofeyer requested a review from Toflar May 13, 2019


Toflar approved these changes May 13, 2019


This comment has been minimized.

Copy link

commented May 13, 2019

Looks good to me.

I wonder if we should refactor those two parts to use a shared function now if we are making changes already. This would make later changes (e.g. if updating the FK behaviour) easier.

Something like this:

function pruneChildRecords(string $childTable, string $parentTable, bool $dynamicPtable = false) : bool {
	$condition = $dynamicPtable ? 'ptable=' . $parentTable . ' AND ' : '';
	$ids = $this->Database->execute('SELECT FROM ' . $childTable . ' c LEFT JOIN ' . $parentTable. ' p ON WHERE ' . $condition . ' IS NULL');

	if (!$ids->numRows) {
		return false;

	return $this->Database
		->execute('DELETE FROM ' . $childTable. ' WHERE id IN(' . implode(',', array_map('\intval', $ids->fetchEach('id'))) . ')')
		->affectedRows > 0;

// call like
$reload |= pruneChildRecords($this->strTable, $ptable, $GLOBALS['TL_DCA'][$this->strTable]['config']['dynamicPtable']);

$reload |= pruneChildRecords($v, $this->strTable, $GLOBALS['TL_DCA'][$v]['config']['dynamicPtable']);

m-vo approved these changes May 13, 2019

@leofeyer leofeyer merged commit 35c682d into 4.4 May 14, 2019

5 checks passed

Travis CI - Branch Build Passed
Travis CI - Pull Request Build Passed
continuous-integration/appveyor/branch AppVeyor build succeeded
continuous-integration/appveyor/pr AppVeyor build succeeded
coverage/coveralls Coverage remained the same at 89.612%

@leofeyer leofeyer deleted the hotfix/optimize-revise-table branch May 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.