Skip to content

Commit

Permalink
Merge pull request #6525 from OCHA-DAP/dev
Browse files Browse the repository at this point in the history
dev into prod
  • Loading branch information
danmihaila authored Jan 28, 2025
2 parents e036681 + 4ba67f3 commit abab857
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ckanext-hdx_package/ckanext/hdx_package/helpers/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import ckan.plugins.toolkit as tk
import ckanext.hdx_theme.helpers.country_list_hardcoded as focus_countries
from ckanext.hdx_theme.helpers.caching import dogpile_standard_config, dogpile_config_filter, dogpile_requests_region, \
HDXRedisInvalidationStrategy
HDXRedisInvalidationStrategy, cache_only_if_truthy_wrapper

log = logging.getLogger(__name__)
config = tk.config
Expand Down Expand Up @@ -193,7 +193,7 @@ def invalidate_cached_resource_id_apihighways():
cached_resource_id_apihighways.invalidate()


@dogpile_requests_region.cache_on_arguments()
@cache_only_if_truthy_wrapper(dogpile_requests_region)
def cached_approved_tags_list():
log.info('Creating cache for approved tags list')
tags = tk.get_action('hdx_retrieve_approved_tags')({'user': '127.0.0.1'}, {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
display: flex;
}
.resource-item .heading .resource-name {
max-width: 400px;
max-width: 390px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
.heading {
display: flex;
.resource-name {
max-width: 400px;
max-width: 390px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
Expand Down
31 changes: 31 additions & 0 deletions ckanext-hdx_theme/ckanext/hdx_theme/helpers/caching.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import logging
from functools import wraps

import requests
import time
# import datetime
# import dateutil.parser

from dogpile.cache import make_region
from dogpile.cache.api import NO_VALUE
from dogpile.cache.region import RegionInvalidationStrategy, CacheRegion

from redis import StrictRedis
Expand Down Expand Up @@ -149,3 +152,31 @@ def cached_make_rest_api_request(url):
response.raise_for_status()

return response.json()

def cache_only_if_truthy_wrapper(region: CacheRegion, *args, **kwargs):
# original_decorator = region.cache_on_arguments(*args, **kwargs)

def decorator(f):
@wraps(f)
def wrapper(*fn_args, **fn_kwargs):
key_generator = region.function_key_generator('only_truthy_values', f)
key = key_generator(*fn_args, *fn_kwargs)

cached_value = region.get(key)
if cached_value is not NO_VALUE:
return cached_value
# Call the original function
result = f(*fn_args, **fn_kwargs)

# Cache the result only if it's truthy
if result:
log.info(f'Caching result for key "{key}"')
region.set(key, result)
else:
log.warning(f'Not caching result for key "{key}" because returned value was: {result}')

return result

return wrapper

return decorator
2 changes: 1 addition & 1 deletion ckanext-hdx_theme/ckanext/hdx_theme/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
hdx_version = 'v1.87.2'
hdx_version = 'v1.87.3'
5 changes: 5 additions & 0 deletions ckanext-hdx_users/ckanext/hdx_users/actions/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ckanext.hdx_users.helpers.reset_password as reset_password
import ckanext.hdx_users.model as umodel
from ckan.types import Context, DataDict
from ckanext.hdx_users.controller_logic import notification_platform_logic
from ckanext.hdx_users.helpers.notification_platform import check_notifications_enabled_for_dataset, read_novu_config
from ckanext.hdx_users.helpers.token_expiration_helper import find_expiring_api_tokens, send_emails_for_expiring_tokens
from ckanext.hdx_users.logic.schema import onboarding_default_update_user_schema
Expand Down Expand Up @@ -132,6 +133,10 @@ def hdx_add_notification_subscription(context: Context, data_dict: DataDict):
email = data_dict.get('email')
dataset_id = data_dict.get('dataset_id')
unsubscribe_token = data_dict.get('unsubscribe_token')
if not unsubscribe_token:
unsubscribe_toke_obj = notification_platform_logic.get_or_generate_unsubscribe_token(email, dataset_id)
data_dict['unsubscribe_token'] = unsubscribe_token = unsubscribe_toke_obj.token
log.warning('unsubscribe token was not provided for: ' + email + ' and ' + dataset_id)
unsubscribe_token_key = 'unsubscribe_token_' + dataset_id.replace('-', '_')

if not email or not dataset_id:
Expand Down
6 changes: 3 additions & 3 deletions hdx-dependency-deploy-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ HDX_GISAPI_URL=https://gallery.ecr.aws/unocha/hdx-postile/
HDX_GISAPI_TAG=1.1.0

HDX_GISLAYER_URL=https://gallery.ecr.aws/unocha/hdx-gislayer/
HDX_GISLAYER_TAG=0.9.3
HDX_GISLAYER_TAG=0.9.4

HDX_GISWORKER_URL=https://gallery.ecr.aws/unocha/hdx-gisworker/
HDX_GISWORKER_TAG=0.9.3
HDX_GISWORKER_TAG=0.9.4

HDX_QAINGEST_URL=https://gallery.ecr.aws/unocha/hdx-jp-sw-qa-ingest/
HDX_QAINGEST_TAG=0.1.3
Expand All @@ -27,4 +27,4 @@ HDX_N8N_IMAGE_URL=https://gallery.ecr.aws/unocha/hdx-n8n/
HDX_N8N_IMAGE_TAG=1.31.2

HDX_N8N_WORKFLOW_URL=https://github.com/OCHA-DAP/hdx-n8n-qa-workflow
HDX_N8N_WORKFLOW_TAG=0.6.1
HDX_N8N_WORKFLOW_TAG=0.7.1

0 comments on commit abab857

Please sign in to comment.