Browse Source

fix issue where blocks could hang if a user does multiple searches per session

2.x
Paul Pound 2 weeks ago
parent
commit
196d4c45c5
  1. 4
      modules/roblib_search_eds/js/eds_results_article.js
  2. 4
      modules/roblib_search_eds/js/eds_results_book.js
  3. 2
      modules/roblib_search_eds/roblib_search_eds.libraries.yml
  4. 18
      modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php
  5. 18
      modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsBooks.php
  6. 4
      modules/solr_site/js/solr_site_bestbet.js
  7. 4
      modules/solr_site/js/solr_site_results.js
  8. 2
      modules/solr_site/roblib_search_solr_site.libraries.yml
  9. 10
      modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php
  10. 10
      modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php

4
modules/roblib_search_eds/js/eds_results_article.js

@ -1,6 +1,8 @@
Drupal.behaviors.roblib_search_eds_articles = { Drupal.behaviors.roblib_search_eds_articles = {
attach: function (context, settings) { attach: function (context, settings) {
if (context == document) { // Run once, when the results container appears. The block may be
// rendered later by BigPipe, so don't rely on context being document.
if (once('roblib-search-eds-articles', '#roblib-search-content-eds-articles', context).length) {
$query = drupalSettings.path.currentPath.replace('roblib_search/', ''); $query = drupalSettings.path.currentPath.replace('roblib_search/', '');
$url = settings.eds_article_search_url + $query; $url = settings.eds_article_search_url + $query;
article_profile = settings.eds_article_profile; article_profile = settings.eds_article_profile;

4
modules/roblib_search_eds/js/eds_results_book.js

@ -1,6 +1,8 @@
Drupal.behaviors.roblib_search_eds = { Drupal.behaviors.roblib_search_eds = {
attach: function (context, settings) { attach: function (context, settings) {
if (context == document) { // Run once, when the results container appears. The block may be
// rendered later by BigPipe, so don't rely on context being document.
if (once('roblib-search-eds-books', '#roblib-search-content-eds', context).length) {
$query = drupalSettings.path.currentPath.replace('roblib_search/', ''); $query = drupalSettings.path.currentPath.replace('roblib_search/', '');
$url = settings.eds_book_search_url + $query; $url = settings.eds_book_search_url + $query;
book_profile = settings.eds_book_profile; book_profile = settings.eds_book_profile;

2
modules/roblib_search_eds/roblib_search_eds.libraries.yml

@ -9,6 +9,7 @@ eds-book:
- core/jquery - core/jquery
- core/drupal - core/drupal
- core/drupalSettings - core/drupalSettings
- core/once
eds-article: eds-article:
version: 1.x version: 1.x
css: css:
@ -20,4 +21,5 @@ eds-article:
- core/jquery - core/jquery
- core/drupal - core/drupal
- core/drupalSettings - core/drupalSettings
- core/once

18
modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsArticles.php

@ -3,6 +3,7 @@
namespace Drupal\roblib_search_eds\Plugin\Block; namespace Drupal\roblib_search_eds\Plugin\Block;
use Drupal\Core\Block\BlockBase; use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
/** /**
* Provides EDS Article search results. * Provides EDS Article search results.
@ -40,10 +41,21 @@ class RoblibSearchEdsArticles extends BlockBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* The block only renders a placeholder and settings; results are fetched
* client side from uncached JSON endpoints, so the markup can be cached.
* Setting max-age 0 here would make BigPipe stream the block in later.
*/ */
public function getCacheMaxAge() { public function getCacheTags() {
// Reading dynamic content from external source so no caching. return Cache::mergeTags(parent::getCacheTags(), ['config:roblib_search_eds.settings']);
return 0; }
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
// The search URL in drupalSettings includes the scheme and host.
return Cache::mergeContexts(parent::getCacheContexts(), ['url.site']);
} }
} }

18
modules/roblib_search_eds/src/Plugin/Block/RoblibSearchEdsBooks.php

@ -3,6 +3,7 @@
namespace Drupal\roblib_search_eds\Plugin\Block; namespace Drupal\roblib_search_eds\Plugin\Block;
use Drupal\Core\Block\BlockBase; use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
/** /**
* Provides EDS book search results. * Provides EDS book search results.
@ -40,10 +41,21 @@ class RoblibSearchEdsBooks extends BlockBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* The block only renders a placeholder and settings; results are fetched
* client side from uncached JSON endpoints, so the markup can be cached.
* Setting max-age 0 here would make BigPipe stream the block in later.
*/ */
public function getCacheMaxAge() { public function getCacheTags() {
// Reading dynamic content from external source so no caching. return Cache::mergeTags(parent::getCacheTags(), ['config:roblib_search_eds.settings']);
return 0; }
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
// The search URL in drupalSettings includes the scheme and host.
return Cache::mergeContexts(parent::getCacheContexts(), ['url.site']);
} }

4
modules/solr_site/js/solr_site_bestbet.js

@ -1,6 +1,8 @@
Drupal.behaviors.roblib_search_solr_bestbet_results = { Drupal.behaviors.roblib_search_solr_bestbet_results = {
attach: function (context, settings) { attach: function (context, settings) {
if (context == document) { // Run once, when the results container appears. The block may be
// rendered later by BigPipe, so don't rely on context being document.
if (once('roblib-search-solr-bestbet', '#roblib-search-content-solr-site-bestbet', context).length) {
query = drupalSettings.path.currentPath.replace('roblib_search/', ''); query = drupalSettings.path.currentPath.replace('roblib_search/', '');
solrUrl = settings.solr_site_search_url + query; solrUrl = settings.solr_site_search_url + query;
baseUrl = settings.solr_bestbet_base_url + query; baseUrl = settings.solr_bestbet_base_url + query;

4
modules/solr_site/js/solr_site_results.js

@ -1,6 +1,8 @@
Drupal.behaviors.roblib_search_solr_site_results = { Drupal.behaviors.roblib_search_solr_site_results = {
attach: function (context, settings) { attach: function (context, settings) {
if (context == document) { // Run once, when the results container appears. The block may be
// rendered later by BigPipe, so don't rely on context being document.
if (once('roblib-search-solr-results', '#roblib-search-content-solr-site-results', context).length) {
unencoded_query = drupalSettings.path.currentPath.replace('roblib_search/', ''); unencoded_query = drupalSettings.path.currentPath.replace('roblib_search/', '');
query = encodeURIComponent(unencoded_query); query = encodeURIComponent(unencoded_query);
solrUrl = settings.solr_site_search_url + query; solrUrl = settings.solr_site_search_url + query;

2
modules/solr_site/roblib_search_solr_site.libraries.yml

@ -9,6 +9,7 @@ solr-site:
- core/jquery - core/jquery
- core/drupal - core/drupal
- core/drupalSettings - core/drupalSettings
- core/once
solr-bestbet: solr-bestbet:
version: 1.x version: 1.x
js: js:
@ -17,3 +18,4 @@ solr-bestbet:
- core/jquery - core/jquery
- core/drupal - core/drupal
- core/drupalSettings - core/drupalSettings
- core/once

10
modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php

@ -3,6 +3,7 @@
namespace Drupal\roblib_search_solr_site\Plugin\Block; namespace Drupal\roblib_search_solr_site\Plugin\Block;
use Drupal\Core\Block\BlockBase; use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
/** /**
* Provides EDS Article search results. * Provides EDS Article search results.
@ -39,10 +40,13 @@ class RoblibSearchSolrSiteBestbet extends BlockBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* The block only renders a placeholder and settings; results are fetched
* client side from uncached JSON endpoints, so the markup can be cached.
* Setting max-age 0 here would make BigPipe stream the block in later.
*/ */
public function getCacheMaxAge() { public function getCacheTags() {
// Reading dynamic content from external source so no caching. return Cache::mergeTags(parent::getCacheTags(), ['config:roblib_search_solr_site.settings']);
return 0;
} }
} }

10
modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php

@ -3,6 +3,7 @@
namespace Drupal\roblib_search_solr_site\Plugin\Block; namespace Drupal\roblib_search_solr_site\Plugin\Block;
use Drupal\Core\Block\BlockBase; use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
/** /**
* Provides EDS book search results. * Provides EDS book search results.
@ -41,10 +42,13 @@ class RoblibSearchSolrsiteGeneral extends BlockBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* The block only renders a placeholder and settings; results are fetched
* client side from uncached JSON endpoints, so the markup can be cached.
* Setting max-age 0 here would make BigPipe stream the block in later.
*/ */
public function getCacheMaxAge() { public function getCacheTags() {
// Reading dynamic content from external source so no caching. return Cache::mergeTags(parent::getCacheTags(), ['config:roblib_search_solr_site.settings']);
return 0;
} }
} }

Loading…
Cancel
Save