Commit 73a2414973ee97b2113ab9a394fcd36e36fbdf35
1 parent
3977c7d0
Exists in
colab
and in
4 other branches
MetricConfigurations cache on MezuroConfiguration's show #46.
Signed-off-by:Beatriz Rezener <beatrizrezener@gmail.com> Signed-off-by:João Gabriel <joaogabrieldebrittoesilva@gmail.com>
Showing
4 changed files
with
15 additions
and
4 deletions
Show diff stats
app/controllers/compound_metric_configurations_controller.rb
| @@ -7,6 +7,8 @@ class CompoundMetricConfigurationsController < BaseMetricConfigurationsControlle | @@ -7,6 +7,8 @@ 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 | + @compound_metric_configuration.configuration_id = params[:mezuro_configuration_id].to_i | ||
| 11 | + Rails.cache.delete("#{@compound_metric_configuration.configuration_id}_metrics") | ||
| 10 | end | 12 | end |
| 11 | 13 | ||
| 12 | def show | 14 | def show |
| @@ -28,6 +30,7 @@ class CompoundMetricConfigurationsController < BaseMetricConfigurationsControlle | @@ -28,6 +30,7 @@ class CompoundMetricConfigurationsController < BaseMetricConfigurationsControlle | ||
| 28 | else | 30 | else |
| 29 | failed_action(format, 'edit') | 31 | failed_action(format, 'edit') |
| 30 | end | 32 | end |
| 33 | + Rails.cache.delete("#{@compound_metric_configuration.configuration_id}_metrics") | ||
| 31 | end | 34 | end |
| 32 | end | 35 | end |
| 33 | 36 |
app/controllers/metric_configurations_controller.rb
| @@ -19,6 +19,8 @@ class MetricConfigurationsController < BaseMetricConfigurationsController | @@ -19,6 +19,8 @@ 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 | + @mezuro_configuration_id = params[:mezuro_configuration_id] | ||
| 23 | + Rails.cache.delete("#{@mezuro_configuration_id}_metrics") | ||
| 22 | end | 24 | end |
| 23 | 25 | ||
| 24 | def edit | 26 | def edit |
| @@ -33,6 +35,7 @@ class MetricConfigurationsController < BaseMetricConfigurationsController | @@ -33,6 +35,7 @@ class MetricConfigurationsController < BaseMetricConfigurationsController | ||
| 33 | if @metric_configuration.update(metric_configuration_params) | 35 | 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.') } | 36 | format.html { redirect_to(mezuro_configuration_path(@metric_configuration.configuration_id), notice: 'Metric Configuration was successfully updated.') } |
| 35 | format.json { head :no_content } | 37 | format.json { head :no_content } |
| 38 | + Rails.cache.delete("#{@metric_configuration.configuration_id}_metrics") | ||
| 36 | else | 39 | else |
| 37 | failed_action(format, 'edit') | 40 | failed_action(format, 'edit') |
| 38 | end | 41 | end |
| @@ -42,9 +45,11 @@ class MetricConfigurationsController < BaseMetricConfigurationsController | @@ -42,9 +45,11 @@ class MetricConfigurationsController < BaseMetricConfigurationsController | ||
| 42 | def destroy | 45 | def destroy |
| 43 | @metric_configuration.destroy | 46 | @metric_configuration.destroy |
| 44 | respond_to do |format| | 47 | respond_to do |format| |
| 45 | - format.html { redirect_to mezuro_configuration_path(params[:mezuro_configuration_id]) } | 48 | + @metric_configuration.configuration_id = params[:mezuro_configuration_id] |
| 49 | + format.html { redirect_to mezuro_configuration_path(@metric_configuration.configuration_id) } | ||
| 46 | format.json { head :no_content } | 50 | format.json { head :no_content } |
| 47 | end | 51 | end |
| 52 | + Rails.cache.delete("#{@metric_configuration.configuration_id}_metrics") | ||
| 48 | end | 53 | end |
| 49 | 54 | ||
| 50 | protected | 55 | 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}_metrics") 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}_metrics").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}_metrics"), as: :metric_configuration %> |
| 31 | <% end %> | 31 | <% end %> |
| 32 | </tbody> | 32 | </tbody> |
| 33 | </table> | 33 | </table> |