From ba8a39db573fe6df2f109e85efb3f415a2437c5d Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Tue, 29 Apr 2014 11:37:42 +0300 Subject: [PATCH 1/5] Fix: Chart type resets to Date/Time when editing #186 --- rd_ui/app/scripts/visualizations/chart.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rd_ui/app/scripts/visualizations/chart.js b/rd_ui/app/scripts/visualizations/chart.js index e0208d358c..0968399886 100644 --- a/rd_ui/app/scripts/visualizations/chart.js +++ b/rd_ui/app/scripts/visualizations/chart.js @@ -101,6 +101,8 @@ } }); + scope.xAxisType = (scope.visualization.options.xAxis && scope.visualization.options.xAxis.type) || scope.xAxisType; + xAxisUnwatch = scope.$watch("xAxisType", function (xAxisType) { scope.visualization.options.xAxis = scope.visualization.options.xAxis || {}; scope.visualization.options.xAxis.type = xAxisType; From fd9d71b9279409f28fb5934e0a94f7b72ff8eaf7 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Tue, 29 Apr 2014 11:57:16 +0300 Subject: [PATCH 2/5] Show error message if failed deleting a visualization --- rd_ui/app/scripts/controllers/query_source.js | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/rd_ui/app/scripts/controllers/query_source.js b/rd_ui/app/scripts/controllers/query_source.js index 075b9dee93..a104e365ee 100644 --- a/rd_ui/app/scripts/controllers/query_source.js +++ b/rd_ui/app/scripts/controllers/query_source.js @@ -1,7 +1,7 @@ (function() { 'use strict'; - function QuerySourceCtrl(Events, $controller, $scope, $location, Query, Visualization, KeyboardShortcuts) { + function QuerySourceCtrl(Events, growl, $controller, $scope, $location, Query, Visualization, KeyboardShortcuts) { // extends QueryViewCtrl $controller('QueryViewCtrl', {$scope: $scope}); // TODO: @@ -67,15 +67,19 @@ if (confirm('Are you sure you want to delete ' + vis.name + ' ?')) { Events.record(currentUser, 'delete', 'visualization', vis.id); - Visualization.delete(vis); - if ($scope.selectedTab == vis.id) { - $scope.selectedTab = DEFAULT_TAB; - $location.hash($scope.selectedTab); - } - $scope.query.visualizations = - $scope.query.visualizations.filter(function(v) { - return vis.id !== v.id; - }); + Visualization.delete(vis, function() { + if ($scope.selectedTab == vis.id) { + $scope.selectedTab = DEFAULT_TAB; + $location.hash($scope.selectedTab); + } + $scope.query.visualizations = + $scope.query.visualizations.filter(function (v) { + return vis.id !== v.id; + }); + }, function () { + growl.addErrorMessage("Error deleting visualization. Maybe it's used in a dashboard?"); + }); + } }; @@ -99,7 +103,7 @@ } angular.module('redash.controllers').controller('QuerySourceCtrl', [ - 'Events', '$controller', '$scope', '$location', 'Query', + 'Events', 'growl', '$controller', '$scope', '$location', 'Query', 'Visualization', 'KeyboardShortcuts', QuerySourceCtrl ]); })(); \ No newline at end of file From 9f2fc1f90a9b82768caa8df361bdbbb3ed6805d5 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Tue, 29 Apr 2014 12:09:38 +0300 Subject: [PATCH 3/5] Workaround for cases when widget is missing but referenced in a dashboard layout (re. #120) --- redash/models.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/redash/models.py b/redash/models.py index a79c48f460..0715020124 100644 --- a/redash/models.py +++ b/redash/models.py @@ -261,7 +261,23 @@ def to_dict(self, with_widgets=False): .switch(Query)\ .join(QueryResult, join_type=peewee.JOIN_LEFT_OUTER) widgets = {w.id: w.to_dict() for w in widgets} - widgets_layout = map(lambda row: map(lambda widget_id: widgets.get(widget_id, None), row), layout) + + # The following is a workaround for cases when the widget object gets deleted without the dashboard layout + # updated. This happens for users with old databases that didn't have a foreign key relationship between + # visualizations and widgets. + # It's temporary until better solution is implemented (we probably should move the position information + # to the widget). + widgets_layout = [] + for row in layout: + new_row = [] + for widget_id in row: + widget = widgets.get(widget_id, None) + if widget: + new_row.append(widget) + + widgets_layout.append(new_row) + + # widgets_layout = map(lambda row: map(lambda widget_id: widgets.get(widget_id, None), row), layout) else: widgets_layout = None From f39a848aa2123e333771fbd2e8ef17ad67299753 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Tue, 29 Apr 2014 12:13:33 +0300 Subject: [PATCH 4/5] Make job expiry time configurable. --- redash/data/worker.py | 2 +- redash/settings.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/redash/data/worker.py b/redash/data/worker.py index fcbbfd774d..5b2fbdafd6 100644 --- a/redash/data/worker.py +++ b/redash/data/worker.py @@ -314,7 +314,7 @@ def _fork_and_process(self, job_id): self.name, job_id) job.done(None, "Interrupted/Cancelled while running.") - job.expire(24 * 3600) + job.expire(settings.JOB_EXPIRY_TIME) logging.info("[%s] Finished Processing %s (pid: %d status: %d)", self.name, job_id, self.child_pid, status) diff --git a/redash/settings.py b/redash/settings.py index a225c1206a..50421354c6 100644 --- a/redash/settings.py +++ b/redash/settings.py @@ -63,6 +63,7 @@ def parse_boolean(str): ALLOWED_EXTERNAL_USERS = array_from_string(os.environ.get("REDASH_ALLOWED_EXTERNAL_USERS", '')) STATIC_ASSETS_PATH = fix_assets_path(os.environ.get("REDASH_STATIC_ASSETS_PATH", "../rd_ui/app/")) WORKERS_COUNT = int(os.environ.get("REDASH_WORKERS_COUNT", "2")) +JOB_EXPIRY_TIME = int(os.environ.get("REDASH_JOB_EXPIRY_TIME", 3600*24)) COOKIE_SECRET = os.environ.get("REDASH_COOKIE_SECRET", "c292a0a3aa32397cdb050e233733900f") LOG_LEVEL = os.environ.get("REDASH_LOG_LEVEL", "INFO") EVENTS_LOG_PATH = os.environ.get("REDASH_EVENTS_LOG_PATH", "") From 6efd830bd48ed6d0aa6669ef114fe695a4d47664 Mon Sep 17 00:00:00 2001 From: Arik Fraimovich Date: Tue, 29 Apr 2014 16:02:10 +0300 Subject: [PATCH 5/5] Fix: return last cached result for ttl=-1 (fix #174) --- redash/models.py | 9 +++++++-- tests/test_models.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/redash/models.py b/redash/models.py index 0715020124..bdc061e072 100644 --- a/redash/models.py +++ b/redash/models.py @@ -133,8 +133,13 @@ def to_dict(self): def get_latest(cls, data_source, query, ttl=0): query_hash = utils.gen_query_hash(query) - query = cls.select().where(cls.query_hash == query_hash, cls.data_source == data_source, - peewee.SQL("retrieved_at + interval '%s second' >= now() at time zone 'utc'", ttl)).order_by(cls.retrieved_at.desc()) + if ttl == -1: + query = cls.select().where(cls.query_hash == query_hash, + cls.data_source == data_source).order_by(cls.retrieved_at.desc()) + else: + query = cls.select().where(cls.query_hash == query_hash, cls.data_source == data_source, + peewee.SQL("retrieved_at + interval '%s second' >= now() at time zone 'utc'", + ttl)).order_by(cls.retrieved_at.desc()) return query.first() diff --git a/tests/test_models.py b/tests/test_models.py index 854929c5b8..4ec0f10e62 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -80,4 +80,14 @@ def test_get_latest_returns_the_most_recent_result(self): found_query_result = models.QueryResult.get_latest(qr.data_source, qr.query, 60) + self.assertEqual(found_query_result.id, qr.id) + + def test_get_latest_returns_the_last_cached_result_for_negative_ttl(self): + yesterday = datetime.datetime.now() + datetime.timedelta(days=-100) + very_old = query_result_factory.create(retrieved_at=yesterday) + + yesterday = datetime.datetime.now() + datetime.timedelta(days=-1) + qr = query_result_factory.create(retrieved_at=yesterday) + found_query_result = models.QueryResult.get_latest(qr.data_source, qr.query, -1) + self.assertEqual(found_query_result.id, qr.id) \ No newline at end of file