contao/import — Issue #2475: Performance problem with DCA list->sorting->root in tree view
Author: aschempp
Created: 2011-11-29 19:37:56+00:00
State: open
Labels: backend, Defect

I found a big performance issue when using a large root ID array in tree view. DC_Table, Line 225 uses the eliminateNestedPages() to drop child records. This function uses getChildRecords to find subpages. Imagine if you have 2000 IDs in the list->sorting->root, this results in 2000 queries for getChildRecords, which in turn does as many subqueries as there are levels.

What we actually need at this position is the IDs of all root records. This can be done using one single database query, so Line 225 should be replaced with:

```
$this->root = $this->Database->execute("SELECT id FROM $table WHERE pid=0 AND id IN (" . implode(',', $GLOBALS['TL_DCA'][$table]['list']['sorting']['root']) . ")")->fetchEach('id');
```

[Download the attachments](http://www.contao.org/tl_files/tickets/2475.zip "Download the attachments of this ticket")
Related issues: #3423

--- _Originally created on August 26th, 2010, at 10:30pm (ID 2475)_