Add caching for step and result fragments [SCI-2830]

This commit is contained in:
Oleksii Kriuchykhin 2018-11-14 11:57:53 +01:00
parent fb309a12b9
commit 380a96dcce
16 changed files with 26 additions and 20 deletions

View file

@ -71,6 +71,7 @@ class Asset < ApplicationRecord
# Needed because Paperclip validatates on creation
after_initialize :filter_paperclip_errors, if: :new_record?
before_destroy :paperclip_delete, prepend: true
after_save { result&.touch; step&.touch }
attr_accessor :file_content, :file_info, :preview_cached

View file

@ -7,7 +7,7 @@ class Checklist < ApplicationRecord
length: { maximum: Constants::TEXT_MAX_LENGTH }
validates :step, presence: true
belongs_to :step, inverse_of: :checklists, optional: true
belongs_to :step, inverse_of: :checklists, touch: true, optional: true
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',

View file

@ -19,17 +19,11 @@ class Result < ApplicationRecord
class_name: 'User',
optional: true
belongs_to :my_module, inverse_of: :results, optional: true
has_one :result_asset,
inverse_of: :result,
dependent: :destroy
has_one :result_asset, inverse_of: :result, dependent: :destroy
has_one :asset, through: :result_asset
has_one :result_table,
inverse_of: :result,
dependent: :destroy
has_one :result_table, inverse_of: :result, dependent: :destroy
has_one :table, through: :result_table
has_one :result_text,
inverse_of: :result,
dependent: :destroy
has_one :result_text, inverse_of: :result, dependent: :destroy
has_many :result_comments, foreign_key: :associated_id, dependent: :destroy
has_many :report_elements, inverse_of: :result, dependent: :destroy

View file

@ -1,7 +1,7 @@
class ResultAsset < ApplicationRecord
validates :result, :asset, presence: true
belongs_to :result, inverse_of: :result_asset, optional: true
belongs_to :result, inverse_of: :result_asset, touch: true, optional: true
belongs_to :asset,
inverse_of: :result_asset,
dependent: :destroy,

View file

@ -2,6 +2,7 @@ class ResultComment < Comment
belongs_to :result,
foreign_key: :associated_id,
inverse_of: :result_comments,
touch: true,
optional: true
validates :result, presence: true

View file

@ -1,7 +1,7 @@
class ResultTable < ApplicationRecord
validates :result, :table, presence: true
belongs_to :result, inverse_of: :result_table, optional: true
belongs_to :result, inverse_of: :result_table, touch: true, optional: true
belongs_to :table,
inverse_of: :result_table,
dependent: :destroy,

View file

@ -4,6 +4,6 @@ class ResultText < ApplicationRecord
presence: true,
length: { maximum: Constants::RICH_TEXT_MAX_LENGTH }
validates :result, presence: true
belongs_to :result, inverse_of: :result_text, optional: true
belongs_to :result, inverse_of: :result_text, touch: true, optional: true
has_many :tiny_mce_assets, inverse_of: :result_text, dependent: :destroy
end

View file

@ -3,6 +3,7 @@ class StepAsset < ApplicationRecord
belongs_to :step,
inverse_of: :step_assets,
touch: true,
optional: true
belongs_to :asset,
inverse_of: :step_asset,

View file

@ -2,6 +2,7 @@ class StepComment < Comment
belongs_to :step,
foreign_key: :associated_id,
inverse_of: :step_comments,
touch: true,
optional: true
validates :step, presence: true

View file

@ -1,6 +1,6 @@
class StepTable < ApplicationRecord
validates :step, :table, presence: true
belongs_to :step, inverse_of: :step_tables, optional: true
belongs_to :step, inverse_of: :step_tables, touch: true, optional: true
belongs_to :table, inverse_of: :step_table, optional: true
end

View file

@ -25,6 +25,7 @@ class Table < ApplicationRecord
has_many :report_elements, inverse_of: :table, dependent: :destroy
after_save :update_ts_index
after_save { result&.touch; step&.touch }
#accepts_nested_attributes_for :table
def self.search(user,

View file

@ -5,8 +5,11 @@ class TinyMceAsset < ApplicationRecord
after_destroy :release_team_space
belongs_to :team, inverse_of: :tiny_mce_assets, optional: true
belongs_to :step, inverse_of: :tiny_mce_assets, optional: true
belongs_to :result_text, inverse_of: :tiny_mce_assets, optional: true
belongs_to :step, inverse_of: :tiny_mce_assets, touch: true, optional: true
belongs_to :result_text,
inverse_of: :tiny_mce_assets,
touch: true,
optional: true
has_attached_file :image,
styles: { large: [Constants::LARGE_PIC_FORMAT, :jpg] },
convert_options: { large: '-quality 100 -strip' }

View file

@ -1,7 +1,7 @@
class UserMyModule < ApplicationRecord
validates :user, :my_module, presence: true
belongs_to :user, inverse_of: :user_my_modules, optional: true
belongs_to :user, inverse_of: :user_my_modules, touch: true, optional: true
belongs_to :assigned_by,
foreign_key: 'assigned_by_id',
class_name: 'User',

View file

@ -5,7 +5,7 @@ class UserTeam < ApplicationRecord
validates :user, presence: true
validates :team, presence: true
belongs_to :user, inverse_of: :user_teams, optional: true
belongs_to :user, inverse_of: :user_teams, touch: true, optional: true
belongs_to :assigned_by,
foreign_key: 'assigned_by_id',
class_name: 'User',

View file

@ -48,7 +48,9 @@
<div id="results" data-module-id="<%= @my_module.id %>">
<% ordered_result_of(@my_module).each do |result| %>
<%= render partial: "result", locals: { result: result } %>
<% cache [current_user, result] do %>
<%= render partial: "result", locals: { result: result } %>
<% end %>
<% end %>
</div>
</div>

View file

@ -25,7 +25,9 @@
<div id="steps">
<% @protocol.steps.order(:position).each do |step| %>
<%= render partial: "steps/step.html.erb", locals: { step: step } %>
<% cache [current_user, step] do %>
<%= render partial: "steps/step.html.erb", locals: { step: step } %>
<% end %>
<% end %>
</div>
<% if @protocol.steps.count == 0 %>