Skip to content

Business intelligence made simple

Load home page faster

Andrewb2a6cd2b2e92
diff --git a/app/controllers/blazer/queries_controller.rb b/app/controllers/blazer/queries_controller.rb
index 382dcf05..29ffdbbf 100644
--- a/app/controllers/blazer/queries_controller.rb
+++ b/app/controllers/blazer/queries_controller.rb
@@ -2,11 +2,15 @@ module Blazer
class QueriesController < BaseController
before_action :set_query, only: [:show, :edit, :update, :destroy]
+ def home
+ end
+
def index
@queries = Blazer::Query.order(:name)
@queries = @queries.includes(:creator) if Blazer.user_class
@trending_queries = Blazer::Audit.group(:query_id).where("created_at > ?", 2.days.ago).having("COUNT(DISTINCT user_id) >= 3").uniq.count(:user_id)
@checks = Blazer::Check.group(:query_id).count
+ render layout: false
end
def new
diff --git a/app/views/blazer/queries/home.html.erb b/app/views/blazer/queries/home.html.erb
new file mode 100644
index 00000000..d77544ab
--- /dev/null
+++ b/app/views/blazer/queries/home.html.erb
@@ -0,0 +1,30 @@
+<div id="queries">
+ <div id="header" style="margin-bottom: 20px;">
+ <div class="pull-right">
+ <%= link_to "New Query", new_query_path, class: "btn btn-info" %>
+ <%= link_to "Dashboards", dashboards_path, class: "btn btn-primary" %>
+ <%= link_to "Checks", checks_path, class: "btn btn-primary" %>
+ </div>
+ <input type="text" placeholder="Start typing a query or person" style="width: 300px; display: inline-block;" autofocus=true class="search form-control" />
+ </div>
+
+ <table class="table">
+ <thead>
+ <tr>
+ <th>Query</th>
+ <th style="width: 20%; text-align: right;">Mastermind</th>
+ </tr>
+ </thead>
+ <tbody class="list">
+ </tbody>
+ </table>
+</div>
+
+<script>
+ $(".list").load("<%= queries_path %>", function () {
+ var options = {
+ valueNames: ['query', 'creator']
+ };
+ var userList = new List('queries', options);
+ });
+</script>
diff --git a/app/views/blazer/queries/index.html.erb b/app/views/blazer/queries/index.html.erb
index ebe49df4..433ced8a 100644
--- a/app/views/blazer/queries/index.html.erb
+++ b/app/views/blazer/queries/index.html.erb
@@ -1,57 +1,29 @@
-<div id="queries">
- <div id="header" style="margin-bottom: 20px;">
- <div class="pull-right">
- <%= link_to "New Query", new_query_path, class: "btn btn-info" %>
- <%= link_to "Dashboards", dashboards_path, class: "btn btn-primary" %>
- <%= link_to "Checks", checks_path, class: "btn btn-primary" %>
- </div>
- <input type="text" placeholder="Start typing a query or person" style="width: 300px; display: inline-block;" autofocus=true class="search form-control" />
- </div>
-
- <table class="table">
- <thead>
- <tr>
- <th>Query</th>
- <th style="width: 20%; text-align: right;">Mastermind</th>
- </tr>
- </thead>
- <tbody class="list">
- <% @queries.each do |query| %>
- <tr>
- <td class="query">
- <%= link_to query.name, query %>
- <span style="color: #ccc;"><%= extract_vars(query.statement).join(", ") %></span>
- <% if query.created_at > 2.days.ago %>
- <small style="font-weight: bold; color: #5cb85c;">NEW</small>
- <% end %>
- <% if @trending_queries[query.id] %>
- <small style="font-weight: bold; color: #f60;">TRENDING</small>
- <% end %>
- <% if @checks[query.id] %>
- <small style="font-weight: bold; color: #f60;">CHECK</small>
- <% end %>
- <div class="hide"><%= query.name.gsub(/\s+/, "") %></div>
- </td>
- <td class="creator text-right text-muted">
- <% if query.respond_to?(:creator) && (creator = query.creator) && creator.respond_to?(Blazer.user_name) %>
- <% name = creator.send(Blazer.user_name) %>
- <% if creator == blazer_user %>
- You
- <div class="hide">me <%= name %></div>
- <% else %>
- <%= name %>
- <% end %>
- <% end %>
- </td>
- </tr>
+<% @queries.each do |query| %>
+ <tr>
+ <td class="query">
+ <%= link_to query.name, query %>
+ <span style="color: #ccc;"><%= extract_vars(query.statement).join(", ") %></span>
+ <% if query.created_at > 2.days.ago %>
+ <small style="font-weight: bold; color: #5cb85c;">NEW</small>
<% end %>
- </tbody>
- </table>
-</div>
-
-<script>
- var options = {
- valueNames: ['query', 'creator']
- };
- var userList = new List('queries', options);
-</script>
+ <% if @trending_queries[query.id] %>
+ <small style="font-weight: bold; color: #f60;">TRENDING</small>
+ <% end %>
+ <% if @checks[query.id] %>
+ <small style="font-weight: bold; color: #f60;">CHECK</small>
+ <% end %>
+ <div class="hide"><%= query.name.gsub(/\s+/, "") %></div>
+ </td>
+ <td class="creator text-right text-muted">
+ <% if query.respond_to?(:creator) && (creator = query.creator) && creator.respond_to?(Blazer.user_name) %>
+ <% name = creator.send(Blazer.user_name) %>
+ <% if creator == blazer_user %>
+ You
+ <div class="hide">me <%= name %></div>
+ <% else %>
+ <%= name %>
+ <% end %>
+ <% end %>
+ </td>
+ </tr>
+<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index d36b4fc4..28bef3c7 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,5 +1,5 @@
Blazer::Engine.routes.draw do
- resources :queries, except: [:index] do
+ resources :queries do
post :run, on: :collection # err on the side of caution
get :tables, on: :collection
end
@@ -7,5 +7,5 @@ Blazer::Engine.routes.draw do
get :run, on: :member
end
resources :dashboards
- root to: "queries#index"
+ root to: "queries#home"
end