From 0a1cec6f391c53eb339668fefd4a74f4a24b1d52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Tue, 6 Oct 2020 15:53:36 -0400 Subject: [PATCH 1/8] Override flask-compress compression algorithm defaults --- dash/dash.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dash/dash.py b/dash/dash.py index cb3f7aae01..acb9b0b7b9 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -280,6 +280,11 @@ def __init__( elif isinstance(server, bool): name = name if name else "__main__" self.server = flask.Flask(name) if server else None + if self.server is not None: + # flask-compress==1.6.0 changed default to ['br', 'gzip'] + # and non-overridable default compression with Brotli is + # causing performance issues + self.server.config["COMPRESS_ALGORITHM"] = ["gzip"] else: raise ValueError("server must be a Flask app or a boolean") From 1d85677248a4cfe292c2741eed7694b4286f2874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Tue, 6 Oct 2020 15:58:22 -0400 Subject: [PATCH 2/8] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a62a864e2..ff4c35c416 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `dash` will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## Unreleased +### Fixed + + ## [1.16.2] - 2020-09-25 ### Fixed - [#1415](https://github.com/plotly/dash/pull/1415) Fix a regression with some layouts callbacks involving dcc.Tabs, not yet loaded dash_table.DataTable and dcc.Graph to not be called From 6a416d769173c9ceee97ae2ac0f7399ed505eef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Tue, 6 Oct 2020 15:59:18 -0400 Subject: [PATCH 3/8] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff4c35c416..ded3b1b5a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## Unreleased ### Fixed - +- [#1426](https://github.com/plotly/dash/pull/1426) Fix a regression caused by `flask-compress==1.6.0` causing performance degradation on server requests ## [1.16.2] - 2020-09-25 ### Fixed From 01bfbcdf01254d86a31aafdb4eb96c1c11020398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Tue, 6 Oct 2020 16:30:42 -0400 Subject: [PATCH 4/8] Apply override only for flask-compress >= 1.6.0 --- dash/dash.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dash/dash.py b/dash/dash.py index acb9b0b7b9..9ee6b52806 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -1,5 +1,6 @@ from __future__ import print_function + import os import sys import collections @@ -20,6 +21,7 @@ import flask from flask_compress import Compress from werkzeug.debug.tbtools import get_current_traceback +from pkg_resources import get_distribution, parse_version import plotly import dash_renderer @@ -49,6 +51,8 @@ from . import _validate from . import _watch +flask_compress_version = parse_version(get_distribution("flask-compress").version) + # Add explicit mapping for map files mimetypes.add_type("application/json", ".map", True) @@ -280,7 +284,9 @@ def __init__( elif isinstance(server, bool): name = name if name else "__main__" self.server = flask.Flask(name) if server else None - if self.server is not None: + if self.server is not None and flask_compress_version >= parse_version( + "1.6.0" + ): # flask-compress==1.6.0 changed default to ['br', 'gzip'] # and non-overridable default compression with Brotli is # causing performance issues From 32a6e4244ae4a048cea7324fce98b436d3e3306a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Tue, 6 Oct 2020 16:35:13 -0400 Subject: [PATCH 5/8] _ prefix for private --- dash/dash.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 9ee6b52806..2d7c54156f 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -51,7 +51,7 @@ from . import _validate from . import _watch -flask_compress_version = parse_version(get_distribution("flask-compress").version) +_flask_compress_version = parse_version(get_distribution("flask-compress").version) # Add explicit mapping for map files mimetypes.add_type("application/json", ".map", True) @@ -284,7 +284,7 @@ def __init__( elif isinstance(server, bool): name = name if name else "__main__" self.server = flask.Flask(name) if server else None - if self.server is not None and flask_compress_version >= parse_version( + if self.server is not None and _flask_compress_version >= parse_version( "1.6.0" ): # flask-compress==1.6.0 changed default to ['br', 'gzip'] From 880df554230e3a1c2f5e518962481b20bb7b97c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Tue, 6 Oct 2020 16:40:45 -0400 Subject: [PATCH 6/8] Apply COMPRESS_ALGORITHM if not already overriden --- dash/dash.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 2d7c54156f..9c6dadffdb 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -284,16 +284,19 @@ def __init__( elif isinstance(server, bool): name = name if name else "__main__" self.server = flask.Flask(name) if server else None - if self.server is not None and _flask_compress_version >= parse_version( - "1.6.0" - ): - # flask-compress==1.6.0 changed default to ['br', 'gzip'] - # and non-overridable default compression with Brotli is - # causing performance issues - self.server.config["COMPRESS_ALGORITHM"] = ["gzip"] else: raise ValueError("server must be a Flask app or a boolean") + if ( + self.server is not None + and not hasattr(self.server.config, "COMPRESS_ALGORITHM") + and _flask_compress_version >= parse_version("1.6.0") + ): + # flask-compress==1.6.0 changed default to ['br', 'gzip'] + # and non-overridable default compression with Brotli is + # causing performance issues + self.server.config["COMPRESS_ALGORITHM"] = ["gzip"] + base_prefix, routes_prefix, requests_prefix = pathname_configs( url_base_pathname, routes_pathname_prefix, requests_pathname_prefix ) From f3fb56f2bb4a0e17f8e9ac2fb81d384b6e1b49b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Tue, 6 Oct 2020 16:42:22 -0400 Subject: [PATCH 7/8] remove extra line --- dash/dash.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dash/dash.py b/dash/dash.py index 9c6dadffdb..71ae894a24 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -1,6 +1,5 @@ from __future__ import print_function - import os import sys import collections From ff1aa4da5495a60847e7c51f5ce37d07c7948355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Tue, 6 Oct 2020 17:22:13 -0400 Subject: [PATCH 8/8] unfix flask-compress --- requires-install.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requires-install.txt b/requires-install.txt index 3079287439..a507a14e2f 100644 --- a/requires-install.txt +++ b/requires-install.txt @@ -1,5 +1,5 @@ Flask>=1.0.2 -flask-compress==1.5.0 +flask-compress plotly dash_renderer==1.8.2 dash-core-components==1.12.1