Repository navigation
Extrem long save time at save items at BE #1153
Copy link
Copy link
Open
Labels
enhancementThis issue is about an enhancement (aka new feature)This issue is about an enhancement (aka new feature)
Milestone
Description
look at contao-community-alliance/dc-general#201
we found the first bottle necks...
1.) ToolboxFile.php
core/src/MetaModels/Helper/ToolboxFile.php
Line 700 in 08b5022
| public static function convertValueToPath($varValue) |
public static function convertValueToPath($varValue)
{
+ if (empty($varValue)) {
+ return '';
+ }
$objFiles = FilesModel::findByPk($varValue);2.) with "MM-1" and attribute select to "MM-2" which also a have relation per select to "MM-3" we found a strong increase of database queries... may be, we can "cache" all existing queries
core/src/MetaModels/MetaModel.php
Line 704 in 08b5022
| public function getIdsFromFilter($objFilter, $strSortBy = '', $intOffset = 0, $intLimit = 0, $strSortOrder = 'ASC') |
...
/**
* The service container.
*
* @var IMetaModelsServiceContainer
*/
protected $serviceContainer;
+
+ private $existingIds = [];
...
public function getIdsFromFilter($objFilter, $strSortBy = '', $intOffset = 0, $intLimit = 0, $strSortOrder = 'ASC')
{
$arrFilteredIds = $this->getMatchingIds($objFilter);
// If desired, sort the entries.
if ($arrFilteredIds && $strSortBy != '') {
if ($objSortAttribute = $this->getAttribute($strSortBy)) {
$arrFilteredIds = $objSortAttribute->sortIds($arrFilteredIds, $strSortOrder);
} elseif (in_array($strSortBy, array('id', 'pid', 'tstamp', 'sorting'))) {
+ if (array_intersect($arrFilteredIds, $this->existingIds) == $arrFilteredIds) {
+ return $arrFilteredIds;
+ }
// Sort by database values.
$arrFilteredIds = $this
->getDatabase()
->prepare(
sprintf(
'SELECT id FROM %s WHERE id IN(%s) ORDER BY %s %s',
$this->getTableName(),
$this->buildDatabaseParameterList($arrFilteredIds),
$strSortBy,
$strSortOrder
)
)
->execute($arrFilteredIds)
->fetchEach('id');
+ $this->existingIds = array_merge($this->existingIds, $arrFilteredIds);
} elseif ($strSortBy == 'random') {
shuffle($arrFilteredIds);
}
}
...Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementThis issue is about an enhancement (aka new feature)This issue is about an enhancement (aka new feature)
Activity
Damsgit commentedon May 29, 2017
I have this message :
Fatal error: Cannot redeclare MetaModels\MetaModel::$serviceContainer in /homepages/4/d406509772/htdocs/.../system/modules/metamodels/classes/src/MetaModels/MetaModel.php on line 692
I can't clear this line ?
protected $serviceContainer;I noted that the save time increases when i have a lot of items in MM (5000 or 10 000 items) before or after the changes.
zonky2 commentedon May 29, 2017
add only
private $existingIds = [];richardhj commentedon Aug 3, 2018
I have one page that accesses different MetaModels. It uses about 1200 database queries to load the site (Contao 4 / Symfony debug console).
I changed the following in the
MetaModel.phpand was able to reduce the number of database queries to about 400(!!!).Maybe there is a way to reach the same result by using doctrine cache / APCu??
zonky2 commentedon Aug 3, 2018
may be it´s a good idea to equalize the terms
private $cache;toprivate $existingIds = [];discordier commentedon Aug 3, 2018
@richardhj Your change introduces a problem when
$attrOnlyis not empty, therefore we can not walk down that road. 😿richardhj commentedon Aug 3, 2018
@discordier Did you ever enabled APCu doctrine cache? Is this available for Contao?
26 remaining items
zonky2 commentedon Jan 23, 2022
Fixed in MM 2.2
zonky2 commentedon Jan 23, 2022
Read any tip to speed up MM: https://metamodels.readthedocs.io/de/latest/cookbook/tips/speed-up-backend-list.html
zonky2 commentedon Aug 23, 2022
Currently there is still the problem in the BE, if many attributes are selected to the filter and there are many items...
@discordier has solution proposals for this