Skip to content

Database slow queries #744

@elvishp2006

Description

@elvishp2006

Version

  • Carbon Fields: 3.1.2
  • WordPress: 5.2.2
  • PHP: 7.2.16

Expected Behavior

Use esc_like to a proper escape and avoid a full scan on tables;

Actual Behavior

The $storage_key is not bein property escaped:

$comparison = $table_column . ' LIKE "' . esc_sql( $storage_key ) . '%"';

Container definition

Container::make( 'theme_options', __( 'Settings' ) )
	->set_page_parent( 'edit.php' )
	->add_fields(
		[
			Field::make( 'rich_text', 'footer_posts', __( 'Footer' ) ),
		]
	);

Steps to Reproduce the Problem

  1. Get the query being generated to get the value of field;
  2. Execute a explain on mysql;
  3. See how many rows are being scaned;

Comments

Example of query being generated:

SELECT option_name AS `key`, option_value AS `value` FROM cp45e3_options WHERE ( option_name = "_footer_posts" OR option_name LIKE "_footer_posts|%" ) ORDER BY option_name ASC

Expected query:

SELECT option_name AS `key`, option_value AS `value` FROM cp45e3_options WHERE  ( option_name = "_footer_posts" OR option_name LIKE "\_footer\_posts|%" ) ORDER BY option_name ASC

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions