From 92ee4fb8c3288ccb3cf1c8ac5c523ebccd6016ca Mon Sep 17 00:00:00 2001 From: Ibrahim Ercan Date: Tue, 16 Feb 2021 20:08:03 +0300 Subject: [PATCH 1/5] fix: thumbnails and reports will be use WEBDRIVER_WINDOW option --- superset/config.py | 2 +- superset/reports/commands/execute.py | 11 +++++++++-- superset/utils/screenshots.py | 26 ++++++++++++++++++++++---- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/superset/config.py b/superset/config.py index 2686f4544ddf9..6ec77e9def8be 100644 --- a/superset/config.py +++ b/superset/config.py @@ -946,7 +946,7 @@ class CeleryConfig: # pylint: disable=too-few-public-methods WEBDRIVER_TYPE = "firefox" # Window size - this will impact the rendering of the data -WEBDRIVER_WINDOW = {"dashboard": (1600, 2000), "slice": (3000, 1200)} +WEBDRIVER_WINDOW = {"dashboard": (1600, 3000), "slice": (1280, 960)} # An optional override to the default auth hook used to provide auth to the # offline webdriver diff --git a/superset/reports/commands/execute.py b/superset/reports/commands/execute.py index ddf4f19cfccb5..075cc8c52c428 100644 --- a/superset/reports/commands/execute.py +++ b/superset/reports/commands/execute.py @@ -152,11 +152,18 @@ def _get_screenshot(self) -> ScreenshotData: screenshot: Optional[BaseScreenshot] = None if self._report_schedule.chart: url = self._get_url(standalone="true") - screenshot = ChartScreenshot(url, self._report_schedule.chart.digest) + screenshot = ChartScreenshot( + url, + self._report_schedule.chart.digest, + window_size=app.config["WEBDRIVER_WINDOW"]["slice"], + thumb_size=app.config["WEBDRIVER_WINDOW"]["slice"] + ) else: url = self._get_url() screenshot = DashboardScreenshot( - url, self._report_schedule.dashboard.digest + url, self._report_schedule.dashboard.digest, + window_size=app.config["WEBDRIVER_WINDOW"]["dashboard"], + thumb_size=app.config["WEBDRIVER_WINDOW"]["dashboard"] ) image_url = self._get_url(user_friendly=True) user = self._get_screenshot_user() diff --git a/superset/utils/screenshots.py b/superset/utils/screenshots.py index 26043616f1268..03e10f0434933 100644 --- a/superset/utils/screenshots.py +++ b/superset/utils/screenshots.py @@ -195,12 +195,30 @@ def resize_image( class ChartScreenshot(BaseScreenshot): thumbnail_type: str = "chart" element: str = "chart-container" - window_size: WindowSize = (800, 600) - thumb_size: WindowSize = (800, 600) + + def __init__(self, + url: str, + digest: str, + window_size: Optional[WindowSize] = None, + thumb_size: Optional[WindowSize] = None + ): + super().__init__(url, digest) + self.window_size = \ + window_size or current_app.config["WEBDRIVER_WINDOW"]["slice"] + self.thumb_size = thumb_size or (800, 600) class DashboardScreenshot(BaseScreenshot): thumbnail_type: str = "dashboard" element: str = "grid-container" - window_size: WindowSize = (1600, int(1600 * 0.75)) - thumb_size: WindowSize = (800, int(800 * 0.75)) + + def __init__(self, + url: str, + digest: str, + window_size: Optional[WindowSize] = None, + thumb_size: Optional[WindowSize] = None + ): + super().__init__(url, digest) + self.window_size = \ + window_size or current_app.config["WEBDRIVER_WINDOW"]["dashboard"] + self.thumb_size = thumb_size or (800, 600) From 2909ab4ef6f309b001ba02ffd0bf35bd2840e63b Mon Sep 17 00:00:00 2001 From: Ibrahim Ercan Date: Thu, 18 Feb 2021 11:25:03 +0300 Subject: [PATCH 2/5] changes reformatted --- superset/reports/commands/execute.py | 7 +++--- superset/utils/screenshots.py | 32 ++++++++++++++++------------ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/superset/reports/commands/execute.py b/superset/reports/commands/execute.py index 075cc8c52c428..0d0f28756bdbf 100644 --- a/superset/reports/commands/execute.py +++ b/superset/reports/commands/execute.py @@ -156,14 +156,15 @@ def _get_screenshot(self) -> ScreenshotData: url, self._report_schedule.chart.digest, window_size=app.config["WEBDRIVER_WINDOW"]["slice"], - thumb_size=app.config["WEBDRIVER_WINDOW"]["slice"] + thumb_size=app.config["WEBDRIVER_WINDOW"]["slice"], ) else: url = self._get_url() screenshot = DashboardScreenshot( - url, self._report_schedule.dashboard.digest, + url, + self._report_schedule.dashboard.digest, window_size=app.config["WEBDRIVER_WINDOW"]["dashboard"], - thumb_size=app.config["WEBDRIVER_WINDOW"]["dashboard"] + thumb_size=app.config["WEBDRIVER_WINDOW"]["dashboard"], ) image_url = self._get_url(user_friendly=True) user = self._get_screenshot_user() diff --git a/superset/utils/screenshots.py b/superset/utils/screenshots.py index 03e10f0434933..053cbf80d44e4 100644 --- a/superset/utils/screenshots.py +++ b/superset/utils/screenshots.py @@ -196,15 +196,17 @@ class ChartScreenshot(BaseScreenshot): thumbnail_type: str = "chart" element: str = "chart-container" - def __init__(self, - url: str, - digest: str, - window_size: Optional[WindowSize] = None, - thumb_size: Optional[WindowSize] = None - ): + def __init__( + self, + url: str, + digest: str, + window_size: Optional[WindowSize] = None, + thumb_size: Optional[WindowSize] = None, + ): super().__init__(url, digest) - self.window_size = \ + self.window_size = ( window_size or current_app.config["WEBDRIVER_WINDOW"]["slice"] + ) self.thumb_size = thumb_size or (800, 600) @@ -212,13 +214,15 @@ class DashboardScreenshot(BaseScreenshot): thumbnail_type: str = "dashboard" element: str = "grid-container" - def __init__(self, - url: str, - digest: str, - window_size: Optional[WindowSize] = None, - thumb_size: Optional[WindowSize] = None - ): + def __init__( + self, + url: str, + digest: str, + window_size: Optional[WindowSize] = None, + thumb_size: Optional[WindowSize] = None, + ): super().__init__(url, digest) - self.window_size = \ + self.window_size = ( window_size or current_app.config["WEBDRIVER_WINDOW"]["dashboard"] + ) self.thumb_size = thumb_size or (800, 600) From 24d3efb99aff8191383fc201a589a3378b2926fe Mon Sep 17 00:00:00 2001 From: Ibrahim Ercan Date: Thu, 18 Feb 2021 14:16:25 +0300 Subject: [PATCH 3/5] config change reverted. thumbnails sizes changed to original --- superset/config.py | 2 +- superset/tasks/thumbnails.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/superset/config.py b/superset/config.py index 6ec77e9def8be..2686f4544ddf9 100644 --- a/superset/config.py +++ b/superset/config.py @@ -946,7 +946,7 @@ class CeleryConfig: # pylint: disable=too-few-public-methods WEBDRIVER_TYPE = "firefox" # Window size - this will impact the rendering of the data -WEBDRIVER_WINDOW = {"dashboard": (1600, 3000), "slice": (1280, 960)} +WEBDRIVER_WINDOW = {"dashboard": (1600, 2000), "slice": (3000, 1200)} # An optional override to the default auth hook used to provide auth to the # offline webdriver diff --git a/superset/tasks/thumbnails.py b/superset/tasks/thumbnails.py index 4ca4f2770e75a..217ce1e0f93ae 100644 --- a/superset/tasks/thumbnails.py +++ b/superset/tasks/thumbnails.py @@ -44,7 +44,7 @@ def cache_chart_thumbnail( logger.warning("No cache set, refusing to compute") return None logger.info("Caching chart: %s", url) - screenshot = ChartScreenshot(url, digest) + screenshot = ChartScreenshot(url, digest, (800, 600), (800, 600)) with session_scope(nullpool=True) as session: user = security_manager.get_user_by_username( current_app.config["THUMBNAIL_SELENIUM_USER"], session=session @@ -68,7 +68,7 @@ def cache_dashboard_thumbnail( logging.warning("No cache set, refusing to compute") return logger.info("Caching dashboard: %s", url) - screenshot = DashboardScreenshot(url, digest) + screenshot = DashboardScreenshot(url, digest, (1600, 1200), (1600, 1200)) with session_scope(nullpool=True) as session: user = security_manager.get_user_by_username( current_app.config["THUMBNAIL_SELENIUM_USER"], session=session From 07a028f76a096dca51abdbaa6ae8b32209e0d5f0 Mon Sep 17 00:00:00 2001 From: Ibrahim Ercan Date: Thu, 18 Feb 2021 14:30:13 +0300 Subject: [PATCH 4/5] typo fix --- superset/tasks/thumbnails.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset/tasks/thumbnails.py b/superset/tasks/thumbnails.py index 217ce1e0f93ae..1a51e6d0985d7 100644 --- a/superset/tasks/thumbnails.py +++ b/superset/tasks/thumbnails.py @@ -68,7 +68,7 @@ def cache_dashboard_thumbnail( logging.warning("No cache set, refusing to compute") return logger.info("Caching dashboard: %s", url) - screenshot = DashboardScreenshot(url, digest, (1600, 1200), (1600, 1200)) + screenshot = DashboardScreenshot(url, digest, (1600, 1200), (800, 600)) with session_scope(nullpool=True) as session: user = security_manager.get_user_by_username( current_app.config["THUMBNAIL_SELENIUM_USER"], session=session From f4cec93ec39b93cdabca4631f9feb2edc9adb4a6 Mon Sep 17 00:00:00 2001 From: Ibrahim Ercan Date: Sun, 28 Feb 2021 13:24:33 +0300 Subject: [PATCH 5/5] bugfix defining defaults in thumbnails.py caused thumbnail caches invalidated. they moved to init. --- superset/tasks/thumbnails.py | 4 ++-- superset/utils/screenshots.py | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/superset/tasks/thumbnails.py b/superset/tasks/thumbnails.py index 1a51e6d0985d7..4ca4f2770e75a 100644 --- a/superset/tasks/thumbnails.py +++ b/superset/tasks/thumbnails.py @@ -44,7 +44,7 @@ def cache_chart_thumbnail( logger.warning("No cache set, refusing to compute") return None logger.info("Caching chart: %s", url) - screenshot = ChartScreenshot(url, digest, (800, 600), (800, 600)) + screenshot = ChartScreenshot(url, digest) with session_scope(nullpool=True) as session: user = security_manager.get_user_by_username( current_app.config["THUMBNAIL_SELENIUM_USER"], session=session @@ -68,7 +68,7 @@ def cache_dashboard_thumbnail( logging.warning("No cache set, refusing to compute") return logger.info("Caching dashboard: %s", url) - screenshot = DashboardScreenshot(url, digest, (1600, 1200), (800, 600)) + screenshot = DashboardScreenshot(url, digest) with session_scope(nullpool=True) as session: user = security_manager.get_user_by_username( current_app.config["THUMBNAIL_SELENIUM_USER"], session=session diff --git a/superset/utils/screenshots.py b/superset/utils/screenshots.py index 053cbf80d44e4..73e0c8c12b691 100644 --- a/superset/utils/screenshots.py +++ b/superset/utils/screenshots.py @@ -204,9 +204,7 @@ def __init__( thumb_size: Optional[WindowSize] = None, ): super().__init__(url, digest) - self.window_size = ( - window_size or current_app.config["WEBDRIVER_WINDOW"]["slice"] - ) + self.window_size = window_size or (800, 600) self.thumb_size = thumb_size or (800, 600) @@ -222,7 +220,5 @@ def __init__( thumb_size: Optional[WindowSize] = None, ): super().__init__(url, digest) - self.window_size = ( - window_size or current_app.config["WEBDRIVER_WINDOW"]["dashboard"] - ) + self.window_size = window_size or (1600, 1200) self.thumb_size = thumb_size or (800, 600)