laravel-cms icon indicating copy to clipboard operation
laravel-cms copied to clipboard

Please Address the n + 1 query issues in rendering blocks and widgets

Open niyazvpp opened this issue 1 year ago • 0 comments

Please the below code in Models/Blade.php. To eliminate n + 1 querying situations, you could use some get request before running the loop inside renderBlocks function and remove self::find($blockID) part for each Block.

`public static function renderBlocks($string) {
    ....
    foreach ($blockIds as $blockId) {
        $content = self::renderBlock($blockId);
        $string = str_replace("[[BLOCK_$blockId]]", $content, $string);
    }
    return $string;
}`

`public static function renderBlock(string $blockId, array $options = []) {
    $block = self::find($blockId);
    if ($block == null) {
        return '';
    }
    ...
}`

niyazvpp avatar Apr 26 '24 02:04 niyazvpp