Skip to content

Business intelligence made simple

Added ability to refresh

Andrew753d86e9575e
diff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rb
index f2aaa02f..8503608e 100644
--- a/app/controllers/blazer/queries_controller.rb
+++ b/app/controllers/blazer/queries_controller.rb
@@ -1,7 +1,7 @@
module Blazer
class QueriesController < BaseController
before_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 Blazer
end
end
+ 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 update
if @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.erb
index 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.rb
index 28bef3c7..7f34eda9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,6 +1,7 @@
Blazer::Engine.routes.draw do
resources :queries do
post :run, on: :collection # err on the side of caution
+ post :refresh, on: :member
get :tables, on: :collection
end
resources :checks, except: [:show] do
diff --git a/lib/blazer/data_source.rb b/lib/blazer/data_source.rb
index 1b8b6a76..232112a9 100644
--- a/lib/blazer/data_source.rb
+++ b/lib/blazer/data_source.rb
@@ -49,7 +49,7 @@ module Blazer
error = nil
cached_at = nil
if 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 value
end
@@ -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 tables
default_schema = postgresql? ? "public" : connection_model.connection_config[:database]
schema = connection_model.connection_config[:schema] || default_schema