Skip to content

Navigation Menu

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

Remove unnecessary SELECT and DELETE when saving a page with page/pagetable fields #314

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 4 commits into
base: dev
Choose a base branch
Loading
from

Conversation

tuomassalo
Copy link

I noticed that when saving pages, the value of each Page and PageTable field is queried. With a big number of such fields this is bad for performance.

I believe guess this PR is safe since Fieldtype.php already has identical logic.

Here's a script to reproduce the extra select:

<?php

$processwirePath = '/var/www/html/';
include($processwirePath . 'index.php');
header('Content-Type: text/plain');

////// Install fixture templates, field and pages.

////// First, clean up previous run (if any).

// Remove pages with template 't'.
$pagesToRemove = $pages->find("template=t");
foreach ($pagesToRemove as $page) $pages->delete($page, true);

// Remove template 't'.
$pTemplate = $templates->get('t');
if ($pTemplate) $templates->delete($pTemplate);

// Remove fields if they exist.
$field = $fields->get('field1');
if ($field) $fields->delete($field);

$field = $fields->get('field2');
if ($field) $fields->delete($field);

$field = $fields->get('field3');
if ($field) $fields->delete($field);

// Create template and fields.

$pTemplate = $templates->add('t');
$pTemplate->save();

$field = $fields->makeItem();
$field->name = 'field1';
$field->type = 'Text';
$field->label = "field1";
$field->inputfield = "InputfieldText";
$field->save();
$pTemplate->fields->add($field);
$pTemplate->save();

$field = $fields->makeItem();
$field->name = 'field2';
$field->type = 'Page';
$field->label = "field2";
$field->inputfield = "InputfieldPage";
$field->save();
$pTemplate->fields->add($field);
$pTemplate->save();

$field = $fields->makeItem();
$field->name = 'field3';
$field->type = 'PageTable';
$field->label = "field3";
$field->inputfield = "InputfieldPageTable";
$field->save();
$pTemplate->fields->add($field);
$pTemplate->save();

////// Fixture complete.

// Create page.
$page = $pages->add('t', '/', 'page-a');

$p = $wire->pages->get("id=" . $page->id);

$p->save();

// Edit a text field.
$p->field1 = 'value1.1';

$wire->database->queryLog(true); // empty the log

// This save() triggers a `SELECT field_field2.data ...` and `SELECT field_field3.data ...`
$p->save();

foreach ($wire->database->getQueryLog() as $query) {
    echo $query . "\n\n";
}

@tuomassalo
Copy link
Author

I added another commit that removes an unnecessary DELETE.

Unfortunately, the delete query is not visible with getQueryLog(), but without the new commit, every time $page->save() is called for a new page (causing an INSERT INTO pages), each Page and PageTable field causes an unnecessary DELETE.

I did not have time to find out why not all queries show with getQueryLog().

@tuomassalo tuomassalo changed the title remove unnecessary select when saving a page with page/pagetable fields Remove unnecessary SELECT and DELETE when saving a page with page/pagetable fields Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.