Skip to content
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

Remove cache invalidation, snippet-bundle already does it #134

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ Tests/Application/.env.*.local
package-lock.json
node_modules/
build/

.php-version
8 changes: 5 additions & 3 deletions Controller/SnippetAreaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SnippetAreaController
private $serializer;

/**
* @var ReferenceStoreInterface
* @var ReferenceStoreInterface|null
*/
private $snippetAreaReferenceStore;

Expand All @@ -77,7 +77,7 @@ public function __construct(
ContentMapperInterface $contentMapper,
StructureResolverInterface $structureResolver,
SerializerInterface $serializer,
ReferenceStoreInterface $snippetReferenceStore,
?ReferenceStoreInterface $snippetReferenceStore,
int $maxAge,
int $sharedMaxAge,
int $cacheLifetime
Expand Down Expand Up @@ -126,7 +126,9 @@ public function getAction(Request $request, string $area): Response
throw new NotFoundHttpException(\sprintf('Snippet for snippet area "%s" does not exist in locale "%s"', $area, $locale));
}

$this->snippetAreaReferenceStore->add($area);
if ($this->snippetAreaReferenceStore) {
$this->snippetAreaReferenceStore->add($area);
}

$resolvedSnippet = $this->structureResolver->resolve(
$snippet,
Expand Down
64 changes: 0 additions & 64 deletions EventSubscriber/SnippetAreaInvalidationSubscriber.php

This file was deleted.

2 changes: 1 addition & 1 deletion Resources/config/controllers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<argument type="service" id="sulu.content.mapper"/>
<argument type="service" id="sulu_headless.structure_resolver"/>
<argument type="service" id="jms_serializer.serializer"/>
<argument type="service" id="sulu_headless.reference_store.snippet_area"/>
<argument type="service" id="sulu_snippet.reference_store.snippet_area" on-invalid="null"/>
<argument>%sulu_http_cache.cache.max_age%</argument>
<argument>%sulu_http_cache.cache.shared_max_age%</argument>
<argument>%sulu_headless.snippet_area.cache_lifetime%</argument>
Expand Down
6 changes: 0 additions & 6 deletions Resources/config/event-subscribers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,5 @@
<tag name="sulu_document_manager.event_subscriber"/>
<tag name="kernel.reset" method="reset"/>
</service>

<service id="sulu_headless.event_subscriber.snippet_area_invalidation" class="Sulu\Bundle\HeadlessBundle\EventSubscriber\SnippetAreaInvalidationSubscriber">
<argument type="service" id="sulu_http_cache.cache_manager" on-invalid="null"/>

<tag name="kernel.event_subscriber" />
</service>
</services>
</container>
6 changes: 0 additions & 6 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,5 @@
<tag name="sulu_website.reference_store" alias="navigation"/>
<tag name="kernel.reset" method="reset"/>
</service>

<service id="sulu_headless.reference_store.snippet_area"
class="Sulu\Bundle\WebsiteBundle\ReferenceStore\ReferenceStore">
<tag name="sulu_website.reference_store" alias="snippet_area"/>
<tag name="kernel.reset" method="reset"/>
</service>
</services>
</container>
2 changes: 1 addition & 1 deletion Tests/Application/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
APP_ENV=test
DATABASE_URL=mysql://[email protected]:3306/su_headless_test
DATABASE_URL=mysql://root:root@127.0.0.1:3306/su_headless_test
16 changes: 15 additions & 1 deletion Tests/Functional/Controller/SnippetAreaControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

use Sulu\Bundle\HeadlessBundle\Tests\Functional\BaseTestCase;
use Sulu\Bundle\HeadlessBundle\Tests\Traits\CreateSnippetTrait;
use Sulu\Bundle\WebsiteBundle\ReferenceStore\ReferenceStoreInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;

class SnippetAreaControllerTest extends BaseTestCase
Expand All @@ -27,6 +29,11 @@ class SnippetAreaControllerTest extends BaseTestCase
*/
private $websiteClient;

/**
* @var ReferenceStoreInterface|null
*/
private $snippetAreaReferenceStore;

public static function setUpBeforeClass(): void
{
self::initPhpcr();
Expand Down Expand Up @@ -62,6 +69,10 @@ public static function setUpBeforeClass(): void
protected function setUp(): void
{
$this->websiteClient = $this->createWebsiteClient();

/** @var ReferenceStoreInterface|null $snippetAreaReferenceStore */
$snippetAreaReferenceStore = self::getContainer()->get('sulu_snippet.reference_store.snippet_area', ContainerInterface::NULL_ON_INVALID_REFERENCE);
$this->snippetAreaReferenceStore = $snippetAreaReferenceStore;
}

/**
Expand Down Expand Up @@ -125,7 +136,10 @@ public function testGetAction(

if (200 === $response->getStatusCode()) {
$this->assertStringContainsString('public', (string) $response->headers->get('Cache-Control'));
$this->assertStringContainsString('snippet_area-default', (string) $response->headers->get('x-cache-tags'));

if ($this->snippetAreaReferenceStore) {
$this->assertStringContainsString('snippet_area-default', (string) $response->headers->get('x-cache-tags'));
}
}

if (null !== $expectedPatternFile) {
Expand Down
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ parameters:
count: 1
path: Content/ContentTypeResolver/ImageMapResolver.php

-
message: "#^Cannot use array destructuring on string\\.$#"
count: 1
path: Content/ContentTypeResolver/PageSelectionResolver.php

-
message: "#^Cannot access offset 0 on mixed\\.$#"
count: 1
Expand Down Expand Up @@ -105,11 +100,6 @@ parameters:
count: 1
path: Content/DataProviderResolver/MediaDataProviderResolver.php

-
message: "#^Cannot use array destructuring on string\\.$#"
count: 1
path: Content/DataProviderResolver/PageDataProviderResolver.php

-
message: "#^PHPDoc tag @var above a method has no effect\\.$#"
count: 1
Expand Down Expand Up @@ -140,11 +130,6 @@ parameters:
count: 1
path: Content/DataProviderResolver/PageDataProviderResolver.php

-
message: "#^Cannot use array destructuring on string\\.$#"
count: 1
path: Content/DataProviderResolver/SnippetDataProviderResolver.php

-
message: "#^PHPDoc tag @var above a method has no effect\\.$#"
count: 1
Expand Down