Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Optimization: prevent an N+1 queries case by automatially fetching sortfields if a PageTable has them #304

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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
Loading
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions 16 wire/modules/Fieldtype/FieldtypePageTable.module
Original file line number Diff line number Diff line change
Expand Up @@ -471,18 +471,24 @@ class FieldtypePageTable extends FieldtypeMulti implements Module, FieldtypeDoes
$loadOptions = array('cache' => false);
if($template) $loadOptions['template'] = $template;

$items = $this->wire()->pages->getById($value, $loadOptions);
$sanitizer = $this->wire()->sanitizer;

$sortfields = $field->get('sortfields');
$sorts = array();
if($sortfields) {
$sorts = array();
$sanitizer = $this->wire()->sanitizer;
foreach(explode(',', $sortfields) as $sortfield) {
$sorts[] = $sanitizer->name(trim($sortfield));
}
if(wireCount($sorts)) $items->sort($sorts);
//autojoin sort fields to avoid N+1 queries in $items->sort()
$loadOptions['joinFields'] = array_map(function($string) {
return str_replace('-', '', $string);
}, $sorts);
}

$items = $this->wire()->pages->getById($value, $loadOptions);

$sortfields = $field->get('sortfields');
if(wireCount($sorts)) $items->sort($sorts);

foreach($items as $item) {
$item->setQuietly('_pageTableField', $field->id);
$item->setQuietly('_pageTableParent', $page->id);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.