Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use a local variable instead of an instance variable

@all_actions_per_context is not used anywhere except for in the
StatsController. It's only used in two functions and it's not used by
anything in the view.

Make it a local variable instead.
  • Loading branch information...
commit f9bd9232055f6d6c24941001ef1edb97f591851a 1 parent d9f4226
@mattr- mattr- authored
Showing with 14 additions and 15 deletions.
  1. +14 −15 app/controllers/stats_controller.rb
View
29 app/controllers/stats_controller.rb
@@ -190,7 +190,7 @@ def context_total_actions_data
# get total action count per context Went from GROUP BY c.id to c.name for
# compatibility with postgresql. Since the name is forced to be unique, this
# should work.
- @all_actions_per_context = current_user.contexts.find_by_sql(
+ all_actions_per_context = current_user.contexts.find_by_sql(
"SELECT c.name AS name, c.id as id, count(*) AS total "+
"FROM contexts c, todos t "+
"WHERE t.context_id=c.id "+
@@ -198,23 +198,23 @@ def context_total_actions_data
"GROUP BY c.name, c.id "+
"ORDER BY total DESC"
)
- @sum = @all_actions_per_context.inject(0){|sum, apc| sum += apc['total'].to_i }
+ @sum = all_actions_per_context.inject(0){|sum, apc| sum += apc['total'].to_i }
pie_cutoff=10
- size = [@all_actions_per_context.size, pie_cutoff].min
+ size = [all_actions_per_context.size, pie_cutoff].min
# explicitely copy contents of hash to avoid ending up with two arrays pointing to same hashes
@actions_per_context = Array.new(size){|i| {
- 'name' => @all_actions_per_context[i][:name],
- 'total' => @all_actions_per_context[i][:total].to_i,
- 'id' => @all_actions_per_context[i][:id]
+ 'name' => all_actions_per_context[i][:name],
+ 'total' => all_actions_per_context[i][:total].to_i,
+ 'id' => all_actions_per_context[i][:id]
} }
if size==pie_cutoff
@actions_per_context[size-1]['name']=t('stats.other_actions_label')
@actions_per_context[size-1]['total']=@actions_per_context[size-1]['total']
@actions_per_context[size-1]['id']=-1
- size.upto(@all_actions_per_context.size-1){ |i| @actions_per_context[size-1]['total']+=(@all_actions_per_context[i]['total'].to_i) }
+ size.upto(all_actions_per_context.size-1){ |i| @actions_per_context[size-1]['total']+=(all_actions_per_context[i]['total'].to_i) }
end
@truncate_chars = 15
@@ -227,7 +227,7 @@ def context_running_actions_data
#
# Went from GROUP BY c.id to c.name for compatibility with postgresql. Since
# the name is forced to be unique, this should work.
- @all_actions_per_context = current_user.contexts.find_by_sql(
+ all_actions_per_context = current_user.contexts.find_by_sql(
"SELECT c.name AS name, c.id as id, count(*) AS total "+
"FROM contexts c, todos t "+
"WHERE t.context_id=c.id AND t.completed_at IS NULL AND NOT c.hide "+
@@ -235,23 +235,23 @@ def context_running_actions_data
"GROUP BY c.name, c.id "+
"ORDER BY total DESC"
)
- @sum = @all_actions_per_context.inject(0){|sum, apc| sum += apc['total'].to_i }
+ @sum = all_actions_per_context.inject(0){|sum, apc| sum += apc['total'].to_i }
pie_cutoff=10
- size = [@all_actions_per_context.size, pie_cutoff].min
+ size = [all_actions_per_context.size, pie_cutoff].min
# explicitely copy contents of hash to avoid ending up with two arrays pointing to same hashes
@actions_per_context = Array.new(size){|i| {
- 'name' => @all_actions_per_context[i][:name],
- 'total' => @all_actions_per_context[i][:total].to_i,
- 'id' => @all_actions_per_context[i][:id]
+ 'name' => all_actions_per_context[i][:name],
+ 'total' => all_actions_per_context[i][:total].to_i,
+ 'id' => all_actions_per_context[i][:id]
} }
if size==pie_cutoff
@actions_per_context[size-1]['name']=t('stats.other_actions_label')
@actions_per_context[size-1]['total']=@actions_per_context[size-1]['total']
@actions_per_context[size-1]['id']=-1
- (size).upto(@all_actions_per_context.size()-1){|i| @actions_per_context[size-1]['total']+=@all_actions_per_context[i]['total'].to_i }
+ (size).upto(all_actions_per_context.size()-1){|i| @actions_per_context[size-1]['total']+=all_actions_per_context[i]['total'].to_i }
end
@truncate_chars = 15
@@ -408,7 +408,6 @@ def done
private
-
def get_unique_tags_of_user
tag_ids = current_user.todos.find_by_sql([
"SELECT DISTINCT tags.id as id "+
Please sign in to comment.
Something went wrong with that request. Please try again.