You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by bk...@apache.org on 2022/08/16 15:27:19 UTC

[superset] branch master updated: Memoize the common_bootstrap_payload (#21018)

This is an automated email from the ASF dual-hosted git repository.

bkyryliuk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 495a205dec Memoize the common_bootstrap_payload (#21018)
495a205dec is described below

commit 495a205dec577097651d929bb2f062b0f5003e2e
Author: Bogdan <b....@gmail.com>
AuthorDate: Tue Aug 16 08:27:12 2022 -0700

    Memoize the common_bootstrap_payload (#21018)
    
    Try patch
    
    Co-authored-by: Bogdan Kyryliuk <bo...@dropbox.com>
---
 superset/views/base.py                | 8 +++++++-
 tests/integration_tests/core_tests.py | 4 +++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/superset/views/base.py b/superset/views/base.py
index fb56af3518..73b9096cd2 100644
--- a/superset/views/base.py
+++ b/superset/views/base.py
@@ -70,6 +70,7 @@ from superset.exceptions import (
     SupersetException,
     SupersetSecurityException,
 )
+from superset.extensions import cache_manager
 from superset.models.helpers import ImportExportMixin
 from superset.reports.models import ReportRecipientType
 from superset.superset_typing import FlaskResponse
@@ -339,8 +340,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())
 
diff --git a/tests/integration_tests/core_tests.py b/tests/integration_tests/core_tests.py
index 471926d6e2..3d92d7c0e0 100644
--- a/tests/integration_tests/core_tests.py
+++ b/tests/integration_tests/core_tests.py
@@ -62,7 +62,7 @@ from superset.connectors.sqla.models import SqlaTable
 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
@@ -1443,6 +1443,8 @@ class TestCore(SupersetTestCase):
         """
         Functions in feature flags don't break bootstrap data serialization.
         """
+        # feature flags are cached
+        cache_manager.cache.clear()
         self.login()
 
         encoded = json.dumps(