feat: add optional garbage collection after requests (#35061)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Maxime Beauchemin
2025-09-16 09:23:39 -07:00
committed by GitHub
parent 966e231f94
commit d0cc6f115b
2 changed files with 13 additions and 0 deletions

View File

@@ -626,6 +626,8 @@ DEFAULT_FEATURE_FLAGS: dict[str, bool] = {
"DATE_RANGE_TIMESHIFTS_ENABLED": False,
# Enable Matrixify feature for matrix-style chart layouts
"MATRIXIFY": False,
# Force garbage collection after every request
"FORCE_GARBAGE_COLLECTION_AFTER_EVERY_REQUEST": False,
}
# ------------------------------

View File

@@ -638,6 +638,17 @@ class SupersetAppInitializer: # pylint: disable=too-many-public-methods
response.headers[k] = v
return response
@self.superset_app.after_request
def cleanup_analytics_memory(response: Response) -> Response:
"""Force garbage collection after each request if feature flag enabled"""
if feature_flag_manager.is_feature_enabled(
"FORCE_GARBAGE_COLLECTION_AFTER_EVERY_REQUEST"
):
import gc
gc.collect()
return response
@self.superset_app.context_processor
def get_common_bootstrap_data() -> dict[str, Any]:
# Import here to avoid circular imports