-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLANET-7331: Optimize Block report queries (#1157)
* PLANET-7331: Optimize Block report queries Ref: https://jira.greenpeace.org/browse/PLANET-7331 * Reduce queries count Query template namespace instead of individual templates
- Loading branch information
Showing
4 changed files
with
73 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Block search regex | ||
* | ||
* @package P4BKS\Search\Block | ||
*/ | ||
|
||
namespace P4GBKS\Search\Block\Sql; | ||
|
||
use P4GBKS\Search\Block\Query\Parameters; | ||
|
||
/** | ||
* Regular expression used in SQL query | ||
*/ | ||
class Like { | ||
/** | ||
* @var Parameters | ||
*/ | ||
private $params; | ||
|
||
/** | ||
* @param Parameters $params Query parameters. | ||
*/ | ||
public function __construct( Parameters $params ) { | ||
$this->params = $params; | ||
} | ||
|
||
/** | ||
* @return string | ||
* @todo: $params->attributes not implemented. | ||
*/ | ||
public function __toString(): string { | ||
$block_ns = $this->params->namespace(); | ||
$block_name = $this->params->name(); | ||
|
||
if ( 'core' === $block_ns ) { | ||
$block = '%'; | ||
} elseif ( 0 === strpos( $block_name, 'core/' ) ) { | ||
$block = explode( '/', $block_name )[1]; | ||
} else { | ||
$name = $block_name ? $block_name : '%'; | ||
$block = $block_ns ? $block_ns . '/%' : $name; | ||
} | ||
$attrs = $this->params->content() ? '%' . $this->params->content() . '%' : '%'; | ||
|
||
return sprintf( '%%<!-- wp:%s %s', $block, $attrs ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters