From 11a5799d9feb6ddd3095eac560b19d34bacfdda7 Mon Sep 17 00:00:00 2001 From: Mihai Postelnicu Date: Thu, 21 Sep 2023 15:08:09 +0300 Subject: [PATCH 1/2] IREXCM-55 Enable Redis caching of all superset data --- docker/pythonpath_dev/superset_config.py | 57 ++++++++++++++++++++---- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/docker/pythonpath_dev/superset_config.py b/docker/pythonpath_dev/superset_config.py index e083fad3c765b..63ad5a7f57a78 100644 --- a/docker/pythonpath_dev/superset_config.py +++ b/docker/pythonpath_dev/superset_config.py @@ -26,6 +26,8 @@ from cachelib.file import FileSystemCache from celery.schedules import crontab +from superset.superset_typing import CacheConfig +from datetime import timedelta logger = logging.getLogger() @@ -65,19 +67,58 @@ def get_env_variable(var_name: str, default: Optional[str] = None) -> str: REDIS_PORT = get_env_variable("REDIS_PORT") REDIS_CELERY_DB = get_env_variable("REDIS_CELERY_DB", "0") REDIS_RESULTS_DB = get_env_variable("REDIS_RESULTS_DB", "1") +REDIS_DATA_DB = get_env_variable("REDIS_DATA_DB", "2") +REDIS_FILTER_DB = get_env_variable("REDIS_FILTER_DB", "3") +REDIS_EXPLORE_DB = get_env_variable("REDIS_EXPLORE_DB", "4") RESULTS_BACKEND = FileSystemCache("/app/superset_home/sqllab") -CACHE_CONFIG = { - "CACHE_TYPE": "RedisCache", - "CACHE_DEFAULT_TIMEOUT": 300, - "CACHE_KEY_PREFIX": "superset_", - "CACHE_REDIS_HOST": REDIS_HOST, - "CACHE_REDIS_PORT": REDIS_PORT, - "CACHE_REDIS_DB": REDIS_RESULTS_DB, +# CACHE_CONFIG = { +# "CACHE_TYPE": "RedisCache", +# "CACHE_DEFAULT_TIMEOUT": 300, +# "CACHE_KEY_PREFIX": "superset_", +# "CACHE_REDIS_HOST": REDIS_HOST, +# "CACHE_REDIS_PORT": REDIS_PORT, +# "CACHE_REDIS_DB": REDIS_RESULTS_DB, +# } +# DATA_CACHE_CONFIG = CACHE_CONFIG + +CACHE_CONFIG: CacheConfig = { + 'CACHE_TYPE': 'RedisCache', + 'CACHE_DEFAULT_TIMEOUT': int(timedelta(days=1).total_seconds()), + 'CACHE_KEY_PREFIX': 'superset_cache_', + 'CACHE_REDIS_HOST': REDIS_HOST, + 'CACHE_REDIS_PORT': REDIS_PORT, + 'CACHE_REDIS_DB': REDIS_RESULTS_DB } -DATA_CACHE_CONFIG = CACHE_CONFIG +# Cache for datasource metadata and query results +DATA_CACHE_CONFIG: CacheConfig = { + 'CACHE_TYPE': 'RedisCache', + 'CACHE_DEFAULT_TIMEOUT': int(timedelta(days=1).total_seconds()), + 'CACHE_KEY_PREFIX': 'superset_data_', + 'CACHE_REDIS_HOST': REDIS_HOST, + 'CACHE_REDIS_PORT': REDIS_PORT, + 'CACHE_REDIS_DB': REDIS_DATA_DB +} + +FILTER_STATE_CACHE_CONFIG: CacheConfig = { + 'CACHE_TYPE': 'RedisCache', + 'CACHE_DEFAULT_TIMEOUT': int(timedelta(days=1).total_seconds()), + 'CACHE_KEY_PREFIX': 'superset_filter_', + 'CACHE_REDIS_HOST': REDIS_HOST, + 'CACHE_REDIS_PORT': REDIS_PORT, + 'CACHE_REDIS_DB': REDIS_FILTER_DB +} + +EXPLORE_FORM_DATA_CACHE_CONFIG: CacheConfig = { + 'CACHE_TYPE': 'RedisCache', + 'CACHE_DEFAULT_TIMEOUT': int(timedelta(days=1).total_seconds()), + 'CACHE_KEY_PREFIX': 'superset_explore_', + 'CACHE_REDIS_HOST': REDIS_HOST, + 'CACHE_REDIS_PORT': REDIS_PORT, + 'CACHE_REDIS_DB': REDIS_EXPLORE_DB +} class CeleryConfig: broker_url = f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_CELERY_DB}" From 99896a9c6430a25f8d3094e564a40073ccfe7fa3 Mon Sep 17 00:00:00 2001 From: mpostelnicu Date: Thu, 21 Sep 2023 16:57:43 +0300 Subject: [PATCH 2/2] IREXCM-55 Enable Redis caching of all superset data - linter error --- .../nativeFilters/FilterBar/FilterControls/FilterControls.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControls.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControls.tsx index dc4350be2700b..1be9e96ce4e75 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControls.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControls.tsx @@ -256,8 +256,8 @@ const FilterControls: FC = ({ : t( 'Applied filters: %s', activeOverflowedFiltersInScope - .map(filter => filter.name ? t(filter.name) : '') - .join(', '), + .map(filter => (filter.name ? t(filter.name) : '')) + .join(', '), ) } dropdownContent={