From dbbd41218fff8d67565fbc67684b70e7bd02266f Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Wed, 10 Jul 2024 18:38:42 +0100 Subject: [PATCH 1/8] fix: remove version from BBCM specimen links --- ckanext/nhm/theme/assets/scripts/bbcm.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ckanext/nhm/theme/assets/scripts/bbcm.js b/ckanext/nhm/theme/assets/scripts/bbcm.js index 257fab95..5583fdc9 100644 --- a/ckanext/nhm/theme/assets/scripts/bbcm.js +++ b/ckanext/nhm/theme/assets/scripts/bbcm.js @@ -224,9 +224,7 @@ function createPopup(latlng, specs) { 'View on the Data Portal'; popupContent += ''; From a8679a0bb9b44d3861d7de68a24fb1dd06b9b7c5 Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Wed, 10 Jul 2024 18:39:25 +0100 Subject: [PATCH 2/8] fix: remove GA code, don't need it anymore --- ckanext/nhm/theme/templates/bbcm.html | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/ckanext/nhm/theme/templates/bbcm.html b/ckanext/nhm/theme/templates/bbcm.html index 69dd10ba..925603cc 100644 --- a/ckanext/nhm/theme/templates/bbcm.html +++ b/ckanext/nhm/theme/templates/bbcm.html @@ -15,23 +15,6 @@ {%- block page %} {{ super() }} - - -
From da336bb710c7f080413a673ed98468ea2d43cda5 Mon Sep 17 00:00:00 2001 From: Josh Humphries Date: Wed, 10 Jul 2024 18:43:01 +0100 Subject: [PATCH 3/8] fix: reinsert + to URL creation --- ckanext/nhm/theme/assets/scripts/bbcm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/nhm/theme/assets/scripts/bbcm.js b/ckanext/nhm/theme/assets/scripts/bbcm.js index 5583fdc9..f2365210 100644 --- a/ckanext/nhm/theme/assets/scripts/bbcm.js +++ b/ckanext/nhm/theme/assets/scripts/bbcm.js @@ -224,7 +224,7 @@ function createPopup(latlng, specs) { 'View on the Data Portal'; popupContent += '
'; From b3cfdd99f077486fda4774361093719a0cac5131 Mon Sep 17 00:00:00 2001 From: Ginger Butcher Date: Fri, 12 Jul 2024 11:54:00 +0100 Subject: [PATCH 4/8] fix: cache iiif status response for 300s and make request timeout after 5s --- ckanext/nhm/lib/utils.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ckanext/nhm/lib/utils.py b/ckanext/nhm/lib/utils.py index 01278043..0c405e16 100644 --- a/ckanext/nhm/lib/utils.py +++ b/ckanext/nhm/lib/utils.py @@ -6,17 +6,22 @@ from ckan.plugins import toolkit import requests +from cachetools import cached, TTLCache +@cached(cache=TTLCache(maxsize=1024, ttl=300)) def get_iiif_status(): - health = {} + health = {'ping': False} url = toolkit.config.get('ckanext.iiif.image_server_url') - r = requests.get(url + '/status') - if r.ok: - health['ping'] = True - response_json = r.json() - else: + try: + r = requests.get(url + '/status', timeout=5) + if r.ok: + health['ping'] = True + response_json = r.json() + else: + response_json = {} + except requests.exceptions.RequestException as e: response_json = {} health['status'] = response_json.get('status') From 95303c255f9953861149f552291bdd53f73445c8 Mon Sep 17 00:00:00 2001 From: Ginger Butcher Date: Fri, 12 Jul 2024 12:30:30 +0100 Subject: [PATCH 5/8] fix: test if status.index route exists --- ckanext/nhm/lib/helpers.py | 15 +++++++++++++++ ckanext/nhm/theme/templates/header.html | 2 ++ 2 files changed, 17 insertions(+) diff --git a/ckanext/nhm/lib/helpers.py b/ckanext/nhm/lib/helpers.py index d434e6cc..ec02c72d 100644 --- a/ckanext/nhm/lib/helpers.py +++ b/ckanext/nhm/lib/helpers.py @@ -19,6 +19,7 @@ from beaker.cache import cache_region from jinja2.filters import do_truncate from lxml import etree, html +from werkzeug.routing import BuildError from ckan import model from ckan.lib import helpers as core_helpers @@ -1627,3 +1628,17 @@ def get_status_indicator(): amber_status = [r for r in status_reports if r['state'] == 'ok'] if len(amber_status) > 0: return 'amber' + + +def route_exists(route): + """ + Simple helper for checking if a flask route exists. + + :param route: endpoint name, as passed to url_for + :return: bool + """ + try: + url = toolkit.url_for(route) + return True + except BuildError: + return False \ No newline at end of file diff --git a/ckanext/nhm/theme/templates/header.html b/ckanext/nhm/theme/templates/header.html index 8fad5f5e..3943dc0c 100755 --- a/ckanext/nhm/theme/templates/header.html +++ b/ckanext/nhm/theme/templates/header.html @@ -9,6 +9,7 @@ {% set status_indicator = h.get_status_indicator() %} {% macro status_icon() %} +{% if h.route_exists('status.index') %}
@@ -22,6 +23,7 @@
+{% endif %} {% endmacro %} From 3305b9edb4909d5c46b09a689d1294a0b1ef9312 Mon Sep 17 00:00:00 2001 From: Ginger Butcher Date: Fri, 12 Jul 2024 13:12:15 +0100 Subject: [PATCH 6/8] fix: remove (probably) unnecessary maxsize of cache --- ckanext/nhm/lib/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/nhm/lib/utils.py b/ckanext/nhm/lib/utils.py index 0c405e16..3a169898 100644 --- a/ckanext/nhm/lib/utils.py +++ b/ckanext/nhm/lib/utils.py @@ -9,7 +9,7 @@ from cachetools import cached, TTLCache -@cached(cache=TTLCache(maxsize=1024, ttl=300)) +@cached(cache=TTLCache(ttl=300)) def get_iiif_status(): health = {'ping': False} From 9a875a4a2cc46b631cc161c51e9448a6bc1c3e10 Mon Sep 17 00:00:00 2001 From: Ginger Butcher Date: Fri, 12 Jul 2024 15:01:56 +0100 Subject: [PATCH 7/8] fix: apparently maxsize was not unnecessary --- ckanext/nhm/lib/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/nhm/lib/utils.py b/ckanext/nhm/lib/utils.py index 3a169898..0c405e16 100644 --- a/ckanext/nhm/lib/utils.py +++ b/ckanext/nhm/lib/utils.py @@ -9,7 +9,7 @@ from cachetools import cached, TTLCache -@cached(cache=TTLCache(ttl=300)) +@cached(cache=TTLCache(maxsize=1024, ttl=300)) def get_iiif_status(): health = {'ping': False} From 28994d36bf81678e1eef94cc94b4457eea2b0309 Mon Sep 17 00:00:00 2001 From: Ginger Butcher Date: Fri, 12 Jul 2024 16:48:37 +0100 Subject: [PATCH 8/8] refactor: reduce size of ttl cache --- ckanext/nhm/lib/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/nhm/lib/utils.py b/ckanext/nhm/lib/utils.py index 0c405e16..89d6c03a 100644 --- a/ckanext/nhm/lib/utils.py +++ b/ckanext/nhm/lib/utils.py @@ -9,7 +9,7 @@ from cachetools import cached, TTLCache -@cached(cache=TTLCache(maxsize=1024, ttl=300)) +@cached(cache=TTLCache(maxsize=10, ttl=300)) def get_iiif_status(): health = {'ping': False}