Skip to content

Commit

Permalink
Workflow index fix (#646)
Browse files Browse the repository at this point in the history
* add cached count columns

* make UI consume cached counters
  • Loading branch information
amyrebecca authored Feb 28, 2019
1 parent b4cd752 commit 91f8ded
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/models/extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.of_type(type)
end
end

belongs_to :workflow
belongs_to :workflow, counter_cache: true

validates :workflow, presence: true
validates :key, presence: true, uniqueness: {scope: [:workflow_id]}
Expand Down
2 changes: 1 addition & 1 deletion app/models/reducer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Reducer < ApplicationRecord
include Configurable
include BelongsToReducible
include BelongsToReducibleCached

enum topic: {
reduce_by_subject: 0,
Expand Down
2 changes: 1 addition & 1 deletion app/models/subject_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class SubjectRule < ApplicationRecord
include RankedModel
ranks :row_order, with_same: :workflow_id

belongs_to :workflow
belongs_to :workflow, counter_cache: true
has_many :subject_rule_effects, dependent: :destroy

validate :valid_condition?
Expand Down
2 changes: 1 addition & 1 deletion app/models/user_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class UserRule < ApplicationRecord
include RankedModel
ranks :row_order, with_same: :workflow_id

belongs_to :workflow
belongs_to :workflow, counter_cache: true
has_many :user_rule_effects, dependent: :destroy

validate :valid_condition?
Expand Down
14 changes: 7 additions & 7 deletions app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<div class="row">
<div class="col-md-12">
<div class="pull-right" style="margin-top: 1em;">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
<i class="glyphicon glyphicon-plus"></i> Add</span>
</button>
</div>

<h2>Projects</h2>

<table class="table table-striped">
Expand Down Expand Up @@ -28,20 +34,14 @@
<td><%= project.id %></td>
<td><%= link_to project.display_name || "No Name", project_path(project) %></td>
<td class="text-muted">N/A</td>
<td><%= project.reducers.count %></td>
<td><%= project.reducers_count %></td>
<td class="text-muted">N/A</td>
<td><%= project.updated_at %></td>
</tr>
<% end %>
</tbody>
</table>

<div class="btn-group pull-right">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
<i class="glyphicon glyphicon-plus"></i> Add</span>
</button>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
Expand Down
2 changes: 1 addition & 1 deletion app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ul class="nav nav-pills">
<li class="active"><a href="#summary" data-toggle="tab">Summary</a></li>
<li class="disabled"><a href="#extractors" data-toggle="tab">Extractors</a></li>
<li><a href="#reducers" data-toggle="tab">Reducers <span class="badge"><%= @project.reducers.count %></span></a></li>
<li><a href="#reducers" data-toggle="tab">Reducers <span class="badge"><%= @project.reducers_count %></span></a></li>
<li class="disabled"><a href="#rules" data-toggle="tab">Rules</a></li>
<li class="disabled"><a href="#requests" data-toggle="tab">Data Requests</a></li>
</ul>
Expand Down
17 changes: 8 additions & 9 deletions app/views/workflows/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<div class="row">
<div class="col-md-12">
<div class="pull-right" style="margin-top: 1em;">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
<i class="glyphicon glyphicon-plus"></i> Add</span>
</button>
</div>
<h2>Workflows</h2>
<table class="table table-striped table-sm">
<colgroup>
Expand Down Expand Up @@ -38,21 +43,15 @@
<td><%= link_to workflow.name || "[Name unknown]", workflow_path([workflow]) %></td>
<td><%= workflow.project_id %></td>
<td><%= workflow.project_name || "[Name unknown]" %></td>
<td><%= workflow.extractors.count %></td>
<td><%= workflow.reducers.count %></td>
<td><%= workflow.subject_rules.count + workflow.user_rules.count %></td>
<td><%= workflow.extractors_count %></td>
<td><%= workflow.reducers_count %></td>
<td><%= (workflow.subject_rules_count||0) + (workflow.user_rules_count||0) %></td>
<td><%= workflow.updated_at %></td>
</tr>
<% end %>
</tbody>
</table>

<div class="btn-group pull-right">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
<i class="glyphicon glyphicon-plus"></i> Add</span>
</button>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
Expand Down
6 changes: 3 additions & 3 deletions app/views/workflows/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</h2>
<ul class="nav nav-pills">
<li class="active"><a href="#summary" data-toggle="tab">Summary</a></li>
<li><a href="#extractors" data-toggle="tab">Extractors <span class="badge"><%= @workflow.extractors.count %></span></a></li>
<li><a href="#reducers" data-toggle="tab">Reducers <span class="badge"><%= @workflow.reducers.count %></span></a></li>
<li><a href="#rules" data-toggle="tab">Rules <span class="badge"><%= @workflow.subject_rules.count + @workflow.user_rules.count %></span></a></li>
<li><a href="#extractors" data-toggle="tab">Extractors <span class="badge"><%= @workflow.extractors_count %></span></a></li>
<li><a href="#reducers" data-toggle="tab">Reducers <span class="badge"><%= @workflow.reducers_count %></span></a></li>
<li><a href="#rules" data-toggle="tab">Rules <span class="badge"><%= @workflow.subject_rules_count + @workflow.user_rules_count %></span></a></li>
<li><a href="#requests" data-toggle="tab">Data Requests <span class="badge"><%= @workflow.data_requests.count %></span></a></li>
<li><a href="#subjects" data-toggle="tab">Subjects</a></li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddExtractorsCountToWorkflows < ActiveRecord::Migration[5.2]
def change
add_column :workflows, :extractors_count, :int
end
end
5 changes: 5 additions & 0 deletions db/migrate/20190228155344_add_reducers_count_to_workflows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddReducersCountToWorkflows < ActiveRecord::Migration[5.2]
def change
add_column :workflows, :reducers_count, :int
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddSubjectRulesCountToWorkflows < ActiveRecord::Migration[5.2]
def change
add_column :workflows, :subject_rules_count, :int
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUserRulesCountToWorkflows < ActiveRecord::Migration[5.2]
def change
add_column :workflows, :user_rules_count, :int
end
end
5 changes: 5 additions & 0 deletions db/migrate/20190228155456_add_reducers_count_to_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddReducersCountToProjects < ActiveRecord::Migration[5.2]
def change
add_column :projects, :reducers_count, :int
end
end
7 changes: 6 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2018_12_17_191627) do
ActiveRecord::Schema.define(version: 2019_02_28_155456) do

# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
Expand Down Expand Up @@ -111,6 +111,7 @@
t.string "display_name"
t.integer "subject_reductions_count"
t.integer "user_reductions_count"
t.integer "reducers_count"
end

create_table "reducers", force: :cascade do |t|
Expand Down Expand Up @@ -261,6 +262,10 @@
t.integer "user_reductions_count"
t.integer "subject_actions_count"
t.integer "user_actions_count"
t.integer "extractors_count"
t.integer "reducers_count"
t.integer "subject_rules_count"
t.integer "user_rules_count"
end

add_foreign_key "classifications", "subjects"
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/project_counters.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace :counters do
task projects: :environment do
Project.reset_column_information
Project.pluck(:id).each do |id|
Project.reset_counters id, :subject_reductions, :user_reductions
Project.reset_counters id, :subject_reductions, :user_reductions, :reducers
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/workflow_counters.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace :counters do
task workflows: :environment do
Workflow.reset_column_information
Workflow.pluck(:id).each do |id|
Workflow.reset_counters id, :extracts, :subject_reductions, :user_reductions, :subject_actions, :user_actions
Workflow.reset_counters id, :extracts, :subject_reductions, :user_reductions, :subject_actions, :user_actions, :extractors, :reducers, :subject_rules, :user_rules
end
end
end
Expand Down

0 comments on commit 91f8ded

Please sign in to comment.