Skip to content

Commit

Permalink
Add compression checker for cart and cache
Browse files Browse the repository at this point in the history
  • Loading branch information
M-arcus committed Sep 1, 2024
1 parent 4897e27 commit 8baca67
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Health\Checker\PerformanceChecker;

use Frosh\Tools\Components\Health\Checker\CheckerInterface;
use Frosh\Tools\Components\Health\HealthCollection;
use Frosh\Tools\Components\Health\SettingsResult;

abstract class AbstractCompressionChecker implements PerformanceCheckerInterface, CheckerInterface
{
public const DOCUMENTATION_URL = 'https://developer.shopware.com/docs/guides/hosting/performance/performance-tweaks.html#using-zstd-instead-of-gzip-for-compression';

public function __construct(
private readonly string $shopwareVersion,
private readonly string $functionality,
private readonly bool $enabled,
private readonly string $method,
) {}

public function collect(HealthCollection $collection): void
{
if (\version_compare('6.6.4.0', $this->shopwareVersion, '>')) {
return;
}

if (!$this->enabled) {
$collection->add(
SettingsResult::warning(
strtolower($this->functionality) . '-compress',
$this->functionality . ' compression',
'disabled',
'enabled',
self::DOCUMENTATION_URL,
),
);

return;
}

if ($this->method === 'gzip') {
$collection->add(
SettingsResult::warning(
strtolower($this->functionality) . '-compression-method',
$this->functionality . ' compression method',
'gzip',
'zstd',
self::DOCUMENTATION_URL,
),
);

return;
}

if ($this->method === 'zstd' && !extension_loaded('zstd')) {
$collection->add(
SettingsResult::error(
$this->functionality . '-compression-method-extension-zstd',
'PHP extension zstd for ' . $this->functionality . ' compression method',
'disabled',
'enabled',
self::DOCUMENTATION_URL,
),
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Health\Checker\PerformanceChecker;

use Symfony\Component\DependencyInjection\Attribute\Autowire;

class CacheCompressionChecker extends AbstractCompressionChecker
{
public function __construct(
#[Autowire('%kernel.shopware_version%')]
string $shopwareVersion,
#[Autowire('Cache')]
string $functionality,
#[Autowire('%shopware.cache.cache_compression%')]
bool $enabled,
#[Autowire('%shopware.cache.cache_compression_method%')]
string $method,
) {
parent::__construct($shopwareVersion, $functionality, $enabled, $method);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Frosh\Tools\Components\Health\Checker\PerformanceChecker;

use Symfony\Component\DependencyInjection\Attribute\Autowire;

class CartCompressionChecker extends AbstractCompressionChecker
{
public function __construct(
#[Autowire('%kernel.shopware_version%')]
string $shopwareVersion,
#[Autowire('Cart')]
string $functionality,
#[Autowire('%shopware.cart.compress%')]
bool $enabled,
#[Autowire('%shopware.cart.compression_method%')]
string $method,
) {
parent::__construct($shopwareVersion, $functionality, $enabled, $method);
}
}

0 comments on commit 8baca67

Please sign in to comment.