1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 16:26:59 +02:00

Fix inadvertent debug mode memory leak issue when using $pages->findMany(), plus optimize PageTable for faster load when sortfield(s) are in use. Per @apeisa / Avoine.

This commit is contained in:
Ryan Cramer
2016-12-19 06:57:37 -05:00
parent 3f758312a6
commit aab97a0b00
2 changed files with 11 additions and 18 deletions

View File

@@ -121,10 +121,11 @@ class PageArrayIterator extends Wire implements \Iterator {
$ids[] = $page->id;
}
$debug = $this->wire('pages');
if($debug) $this->wire('pages')->debug(false);
$this->pages = $this->wire('pages')->getById($ids, $options);
if($debug) $this->wire('pages')->debug(true);
$pages = $this->wire('pages');
$debug = $pages->debug();
if($debug) $pages->debug(false);
$this->pages = $pages->getById($ids, $options);
if($debug) $pages->debug(true);
}
$this->pagesCount = count($this->pages);

View File

@@ -405,25 +405,17 @@ class FieldtypePageTable extends FieldtypeMulti implements Module {
$loadOptions = array('cache' => false);
if($template) $loadOptions['template'] = $template;
$sortfields = $field->get('sortfields');
$items = $this->wire('pages')->getById($value, $loadOptions);
$sortfields = $field->get('sortfields');
if($sortfields) {
$selector = $template ? "template=$template, " : "";
$selector .= "include=unpublished, id=" . implode('|', $value);
$sorts = array();
foreach(explode(',', $sortfields) as $sortfield) {
$selector .= ", sort=" . $this->wire('sanitizer')->name(trim($sortfield));
$sorts[] = $this->wire('sanitizer')->name(trim($sortfield));
}
$options = array(
'cache' => false,
'caller' => $this->className() . '::wakeupValue',
'loadOptions' => $loadOptions
);
$items = $this->wire('pages')->find($selector, $options);
} else {
$items = $this->wire('pages')->getById($value, $loadOptions);
if(count($sorts)) $items->sort($sorts);
}
return $items;
}