I made several tests to figure out what could possibly slow down the data-output. I work with getPage and a custom snippet that gets the data from the database.
With the following code the load time is at about 0.8s: (Note that I don’t loop through the results to generate the output)
$offset = $modx->getOption('offset',$scriptProperties,0);
$limit = $modx->getOption('limit',$scriptProperties,50);
$sort = $modx->getOption('sort',$scriptProperties,'approvedon');
$dir = $modx->getOption('dir',$scriptProperties,'DESC');
$c = $modx->newQuery('Supporter');
$c->where(array(
'locked' => 0,
'approved' => 1,
));
$c->sortby($sort,$dir);
//for getPage
$total = $modx->getCount('Supporter',$c);
$modx->setPlaceholder('total',$total);
$c->limit($limit,$offset);
$supporters = $modx->getIterator('Supporter', $c);
// Without looping through the results
$modx->setPlaceholder('supporterList', $output);
With this code I get load times at about 1.68s:
$offset = $modx->getOption('offset',$scriptProperties,0);
$limit = $modx->getOption('limit',$scriptProperties,50);
$sort = $modx->getOption('sort',$scriptProperties,'approvedon');
$dir = $modx->getOption('dir',$scriptProperties,'DESC');
$c = $modx->newQuery('Supporter');
$c->where(array(
'locked' => 0,
'approved' => 1,
));
$c->sortby($sort,$dir);
//for getPage
$total = $modx->getCount('Supporter',$c);
$modx->setPlaceholder('total',$total);
$c->limit($limit,$offset);
$supporters = $modx->getIterator('Supporter', $c);
foreach ($supporters as $supporter) {
$supporterArray = $supporter->toArray();
$output .= $modx->getChunk('supporterList', $supporterArray);
}
$modx->setPlaceholder('supporterList', $output);
When I output just one field it saves me just 0.15s
$output .= $supporterArray['name'];
I also tried it with Rowboat and caching the results but I got the almost same load time.
I just figured out that the use of $c->select($modx->getSelectColumns('Supporter','Supporter','',array('id','name'))); slows down the page load by 0.25s at average.
[ed. note: mike85 last edited this post 14 years, 4 months ago.]