Skip to content

Commit

Permalink
Merge pull request #55 from City-of-Helsinki/UHF-X-disable-etusivu-in…
Browse files Browse the repository at this point in the history
…validation

Remove cache invalidation on Etusivu
  • Loading branch information
tuutti authored Apr 24, 2024
2 parents dfe38c9 + 4af72a1 commit 02b79c1
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion helfi_navigation.module
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function helfi_navigation_page_attachments(array &$attachments) : void {
*/
function helfi_navigation_form_node_form_alter(
array &$form,
FormStateInterface $form_state
FormStateInterface $form_state,
) :void {
assert($form_state->getFormObject() instanceof EntityFormInterface);
/** @var \Drupal\node\NodeInterface $node */
Expand Down
2 changes: 1 addition & 1 deletion src/ApiManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function withBypassCache() : self {
public function get(
string $langcode,
string $menuId,
array $options = []
array $options = [],
) : ApiResponse {
$key = $this->getCacheKey(sprintf('external_menu:%s:%s', $menuId, $langcode), $options);

Expand Down
2 changes: 1 addition & 1 deletion src/Event/MenuTreeBuilderLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class MenuTreeBuilderLink extends Event {
public function __construct(
public Url $url,
public string $language,
public array $item
public array $item,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/ExternalMenuTreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private function transform(array $items, array $options): array {
private function createLink(
object $item,
string $menu,
bool $expand_all_items
bool $expand_all_items,
): array {
$link_definition = [
'menu_name' => $menu,
Expand Down
4 changes: 2 additions & 2 deletions src/Menu/MenuTreeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(
private readonly InternalDomainResolver $domainResolver,
private readonly MenuLinkTreeInterface $menuTree,
private readonly MenuLinkManagerInterface $menuLinkManager,
private readonly EventDispatcherInterface $eventDispatcher
private readonly EventDispatcherInterface $eventDispatcher,
) {
}

Expand All @@ -68,7 +68,7 @@ public function build(
string $menuName,
string $langcode,
object $rootElement = NULL,
MenuTreeParameters $parameters = NULL
MenuTreeParameters $parameters = NULL,
): array {
if (!$parameters) {
$parameters = new MenuTreeParameters();
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Block/MenuBlockBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function create(
ContainerInterface $container,
array $configuration,
$plugin_id,
$plugin_definition
$plugin_definition,
) : static {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->logger = $container->get('logger.channel.helfi_navigation');
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Block/MobileMenuFallbackBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function create(
ContainerInterface $container,
array $configuration,
$plugin_id,
$plugin_definition
$plugin_definition,
): static {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->configFactory = $container->get('config.factory');
Expand Down
9 changes: 2 additions & 7 deletions src/Plugin/QueueWorker/MenuQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\helfi_api_base\Cache\CacheTagInvalidatorInterface;
use Drupal\helfi_api_base\Environment\Project;
use Drupal\helfi_navigation\MainMenuManager;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand Down Expand Up @@ -67,7 +66,8 @@ public function processItem($data) : void {
$this->mainMenuManager->sync($language);
}
catch (\Throwable) {
// The failed sync will be logged by ApiManager.
// Don't invalidate remote caches if sync failed.
return;
}
}

Expand All @@ -80,11 +80,6 @@ public function processItem($data) : void {
// locally.
sprintf('external_menu:%s:%s', $menuName, $language),
]);
$this->cacheTagInvalidator->invalidateTags([
// This is used by REST API collection endpoint on Etusivu.
'config:rest.resource.helfi_global_menu_collection',
], [Project::ETUSIVU]);

}

}
2 changes: 1 addition & 1 deletion tests/src/Traits/MenuLinkTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function createNodeWithAlias() : NodeInterface {
* The menu link.
*/
protected function createTestLink(
array $overrides = []
array $overrides = [],
) : MenuLinkContentInterface {
$defaults = [
'menu_name' => 'main',
Expand Down
6 changes: 3 additions & 3 deletions tests/src/Unit/ApiManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ private function getTimeMock(int $expectedTime) : ObjectProphecy {
* The api client.
*/
private function getApiClientMock(
ClientInterface $httpClient,
TimeInterface $time = NULL,
EnvironmentResolverInterface $environmentResolver = NULL,
ClientInterface $httpClient,
TimeInterface $time = NULL,
EnvironmentResolverInterface $environmentResolver = NULL,
): ApiClient {
if (!$time) {
$time = $this->getTimeMock(time())->reveal();
Expand Down
5 changes: 0 additions & 5 deletions tests/src/Unit/Plugin/QueueWorker/MenuQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Drupal\helfi_api_base\Azure\PubSub\PubSubManagerInterface;
use Drupal\helfi_api_base\Cache\CacheTagInvalidator;
use Drupal\helfi_api_base\Cache\CacheTagInvalidatorInterface;
use Drupal\helfi_api_base\Environment\Project;
use Drupal\helfi_navigation\MainMenuManager;
use Drupal\helfi_navigation\Plugin\QueueWorker\MenuQueue;
use Drupal\Tests\UnitTestCase;
Expand Down Expand Up @@ -84,10 +83,6 @@ public function testCacheInvalidator() : void {
'external_menu:main:fi',
])
->shouldBeCalled();
$cacheTagInvalidator->invalidateTags([
'config:rest.resource.helfi_global_menu_collection',
], [Project::ETUSIVU])
->shouldBeCalled();

$container->set('helfi_api_base.cache_tag_invalidator', $cacheTagInvalidator->reveal());
$sut = MenuQueue::create($container, [], '', []);
Expand Down

0 comments on commit 02b79c1

Please sign in to comment.