mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-11 15:45:34 +08:00
Add caching for step and result fragments [SCI-2830]
This commit is contained in:
parent
fb309a12b9
commit
380a96dcce
16 changed files with 26 additions and 20 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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' }
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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 %>
|
||||
|
|
Loading…
Add table
Reference in a new issue