Business intelligence made simple
Added ability to refresh
Andrew753d86e9575e
diff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rbindex f2aaa02f..8503608e 100644--- a/app/controllers/blazer/queries_controller.rb+++ b/app/controllers/blazer/queries_controller.rb@@ -1,7 +1,7 @@module Blazerclass QueriesController < BaseControllerbefore_action :set_queries, only: [:home, :index]- before_action :set_query, only: [:show, :edit, :update, :destroy]+ before_action :set_query, only: [:show, :edit, :update, :destroy, :refresh]def home@queries = @queries.limit(1000)@@ -117,6 +117,12 @@ module Blazerendend+ def refresh+ data_source = Blazer.data_sources[@query.data_source]+ data_source.clear_cache(@query.statement)+ redirect_to query_path(@query, variable_params)+ end+def updateif @query.update(query_params)redirect_to query_path(@query, variable_params)diff --git a/app/views/blazer/queries/run.html.erb b/app/views/blazer/queries/run.html.erbindex 2acd703b..5657b009 100644--- a/app/views/blazer/queries/run.html.erb+++ b/app/views/blazer/queries/run.html.erb@@ -9,7 +9,12 @@<% else %><% unless @only_chart %><% if @cached_at %>- <p class="text-muted" style="float: right;">Cached <%= time_ago_in_words(@cached_at) %> ago</p>+ <p class="text-muted" style="float: right;">+ Cached <%= time_ago_in_words(@cached_at) %> ago+ <% if @query && !params[:data_source] %>+ <%= link_to "Refresh", refresh_query_path(@query, variable_params), method: :post %>+ <% end %>+ </p><% end %><p class="text-muted"><%= pluralize(@rows.size, "row") %></p><% end %>diff --git a/config/routes.rb b/config/routes.rbindex 28bef3c7..7f34eda9 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -1,6 +1,7 @@Blazer::Engine.routes.draw doresources :queries dopost :run, on: :collection # err on the side of caution+ post :refresh, on: :memberget :tables, on: :collectionendresources :checks, except: [:show] dodiff --git a/lib/blazer/data_source.rb b/lib/blazer/data_source.rbindex 1b8b6a76..232112a9 100644--- a/lib/blazer/data_source.rb+++ b/lib/blazer/data_source.rb@@ -49,7 +49,7 @@ module Blazererror = nilcached_at = nilif cache- cache_key = ["blazer", "v2", id, Digest::MD5.hexdigest(statement)].join("/")+ cache_key = self.cache_key(statement)value = Blazer.cache.read(cache_key)rows, cached_at = Marshal.load(value) if valueend@@ -91,6 +91,14 @@ module Blazer[rows, error, cached_at]end+ def clear_cache(statement)+ Blazer.cache.delete(cache_key(statement))+ end++ def cache_key(statement)+ ["blazer", "v2", id, Digest::MD5.hexdigest(statement)].join("/")+ end+def tablesdefault_schema = postgresql? ? "public" : connection_model.connection_config[:database]schema = connection_model.connection_config[:schema] || default_schema