Commit b8b42402d845b4e48b4b4a2bdd4cb2de6e4549ea
Exists in
colab
and in
4 other branches
Merge pull request #150 from beatrizrezener/issue46
MetricConfigurations cache on MezuroConfiguration's show #46.
Showing
4 changed files
with
11 additions
and
3 deletions
Show diff stats
app/controllers/compound_metric_configurations_controller.rb
| @@ -7,6 +7,7 @@ class CompoundMetricConfigurationsController < BaseMetricConfigurationsControlle | @@ -7,6 +7,7 @@ class CompoundMetricConfigurationsController < BaseMetricConfigurationsControlle | ||
| 7 | respond_to do |format| | 7 | respond_to do |format| |
| 8 | create_and_redir(format) | 8 | create_and_redir(format) |
| 9 | end | 9 | end |
| 10 | + Rails.cache.delete("#{params[:mezuro_configuration_id].to_i}_metric_configurations") | ||
| 10 | end | 11 | end |
| 11 | 12 | ||
| 12 | def show | 13 | def show |
| @@ -28,6 +29,7 @@ class CompoundMetricConfigurationsController < BaseMetricConfigurationsControlle | @@ -28,6 +29,7 @@ class CompoundMetricConfigurationsController < BaseMetricConfigurationsControlle | ||
| 28 | else | 29 | else |
| 29 | failed_action(format, 'edit') | 30 | failed_action(format, 'edit') |
| 30 | end | 31 | end |
| 32 | + Rails.cache.delete("#{@compound_metric_configuration.configuration_id}_metric_configurations") | ||
| 31 | end | 33 | end |
| 32 | end | 34 | end |
| 33 | 35 |
app/controllers/metric_configurations_controller.rb
| @@ -19,6 +19,7 @@ class MetricConfigurationsController < BaseMetricConfigurationsController | @@ -19,6 +19,7 @@ class MetricConfigurationsController < BaseMetricConfigurationsController | ||
| 19 | respond_to do |format| | 19 | respond_to do |format| |
| 20 | create_and_redir(format) | 20 | create_and_redir(format) |
| 21 | end | 21 | end |
| 22 | + Rails.cache.delete("#{params[:mezuro_configuration_id]}_metric_configurations") | ||
| 22 | end | 23 | end |
| 23 | 24 | ||
| 24 | def edit | 25 | def edit |
| @@ -33,6 +34,7 @@ class MetricConfigurationsController < BaseMetricConfigurationsController | @@ -33,6 +34,7 @@ class MetricConfigurationsController < BaseMetricConfigurationsController | ||
| 33 | if @metric_configuration.update(metric_configuration_params) | 34 | if @metric_configuration.update(metric_configuration_params) |
| 34 | format.html { redirect_to(mezuro_configuration_path(@metric_configuration.configuration_id), notice: 'Metric Configuration was successfully updated.') } | 35 | format.html { redirect_to(mezuro_configuration_path(@metric_configuration.configuration_id), notice: 'Metric Configuration was successfully updated.') } |
| 35 | format.json { head :no_content } | 36 | format.json { head :no_content } |
| 37 | + Rails.cache.delete("#{@metric_configuration.configuration_id}_metric_configurations") | ||
| 36 | else | 38 | else |
| 37 | failed_action(format, 'edit') | 39 | failed_action(format, 'edit') |
| 38 | end | 40 | end |
| @@ -45,6 +47,7 @@ class MetricConfigurationsController < BaseMetricConfigurationsController | @@ -45,6 +47,7 @@ class MetricConfigurationsController < BaseMetricConfigurationsController | ||
| 45 | format.html { redirect_to mezuro_configuration_path(params[:mezuro_configuration_id]) } | 47 | format.html { redirect_to mezuro_configuration_path(params[:mezuro_configuration_id]) } |
| 46 | format.json { head :no_content } | 48 | format.json { head :no_content } |
| 47 | end | 49 | end |
| 50 | + Rails.cache.delete("#{params[:mezuro_configuration_id]}_metric_configurations") | ||
| 48 | end | 51 | end |
| 49 | 52 | ||
| 50 | protected | 53 | protected |
app/controllers/mezuro_configurations_controller.rb
| @@ -28,7 +28,9 @@ class MezuroConfigurationsController < ApplicationController | @@ -28,7 +28,9 @@ class MezuroConfigurationsController < ApplicationController | ||
| 28 | # GET /mezuro_configurations/1.json | 28 | # GET /mezuro_configurations/1.json |
| 29 | def show | 29 | def show |
| 30 | set_mezuro_configuration | 30 | set_mezuro_configuration |
| 31 | - @mezuro_configuration_metric_configurations = @mezuro_configuration.metric_configurations | 31 | + Rails.cache.fetch("#{@mezuro_configuration.id}_metric_configurations") do |
| 32 | + @mezuro_configuration.metric_configurations | ||
| 33 | + end | ||
| 32 | end | 34 | end |
| 33 | 35 | ||
| 34 | # GET /mezuro_configurations/1/edit | 36 | # GET /mezuro_configurations/1/edit |
| @@ -57,6 +59,7 @@ class MezuroConfigurationsController < ApplicationController | @@ -57,6 +59,7 @@ class MezuroConfigurationsController < ApplicationController | ||
| 57 | format.html { redirect_to mezuro_configurations_url } | 59 | format.html { redirect_to mezuro_configurations_url } |
| 58 | format.json { head :no_content } | 60 | format.json { head :no_content } |
| 59 | end | 61 | end |
| 62 | + Rails.cache.delete("#{@mezuro_configuration.id}_metrics") | ||
| 60 | end | 63 | end |
| 61 | 64 | ||
| 62 | private | 65 | private |
app/views/mezuro_configurations/show.html.erb
| @@ -24,10 +24,10 @@ | @@ -24,10 +24,10 @@ | ||
| 24 | </tr> | 24 | </tr> |
| 25 | </thead> | 25 | </thead> |
| 26 | <tbody> | 26 | <tbody> |
| 27 | - <% if @mezuro_configuration_metric_configurations.empty? %> | 27 | + <% if Rails.cache.read("#{@mezuro_configuration.id}_metric_configurations").empty? %> |
| 28 | <%= render partial: 'no_metric_configurations' %> | 28 | <%= render partial: 'no_metric_configurations' %> |
| 29 | <% else %> | 29 | <% else %> |
| 30 | - <%= render partial: 'metric_configurations', collection: @mezuro_configuration_metric_configurations, as: :metric_configuration %> | 30 | + <%= render partial: 'metric_configurations', collection: Rails.cache.read("#{@mezuro_configuration.id}_metric_configurations"), as: :metric_configuration %> |
| 31 | <% end %> | 31 | <% end %> |
| 32 | </tbody> | 32 | </tbody> |
| 33 | </table> | 33 | </table> |