Skip to content

Commit

Permalink
Memoize the common_bootstrap_payload (apache#21018)
Browse files Browse the repository at this point in the history
Try patch

Co-authored-by: Bogdan Kyryliuk <[email protected]>
(cherry picked from commit 495a205)
  • Loading branch information
bkyryliuk authored and Fahrenheit35 committed Nov 11, 2022
1 parent e8737ba commit 39f1b02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
SupersetException,
SupersetSecurityException,
)
from superset.extensions import cache_manager
from superset.models.helpers import ImportExportMixin
from superset.models.reports import ReportRecipientType
from superset.superset_typing import FlaskResponse
Expand Down Expand Up @@ -343,8 +344,13 @@ def menu_data() -> Dict[str, Any]:
}


@cache_manager.cache.memoize(timeout=60)
def common_bootstrap_payload() -> Dict[str, Any]:
"""Common data always sent to the client"""
"""Common data always sent to the client
The function is memoized as the return value only changes based
on configuration and feature flag values.
"""
messages = get_flashed_messages(with_categories=True)
locale = str(get_locale())

Expand Down
4 changes: 3 additions & 1 deletion tests/integration_tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
from superset.db_engine_specs.base import BaseEngineSpec
from superset.db_engine_specs.mssql import MssqlEngineSpec
from superset.exceptions import SupersetException
from superset.extensions import async_query_manager
from superset.extensions import async_query_manager, cache_manager
from superset.models import core as models
from superset.models.annotations import Annotation, AnnotationLayer
from superset.models.dashboard import Dashboard
Expand Down Expand Up @@ -1400,6 +1400,8 @@ def test_feature_flag_serialization(self):
"""
Functions in feature flags don't break bootstrap data serialization.
"""
# feature flags are cached
cache_manager.cache.clear()
self.login()

encoded = json.dumps(
Expand Down

0 comments on commit 39f1b02

Please sign in to comment.