Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Matt Rogers authored September 08, 2012

Showing 1 changed file with 14 additions and 15 deletions. Show diff stats Hide diff stats

  1. 29  app/controllers/stats_controller.rb
29  app/controllers/stats_controller.rb
@@ -190,7 +190,7 @@ def context_total_actions_data
190 190
     # get total action count per context Went from GROUP BY c.id to c.name for
191 191
     # compatibility with postgresql. Since the name is forced to be unique, this
192 192
     # should work.
193  
-    @all_actions_per_context = current_user.contexts.find_by_sql(
  193
+    all_actions_per_context = current_user.contexts.find_by_sql(
194 194
       "SELECT c.name AS name, c.id as id, count(*) AS total "+
195 195
         "FROM contexts c, todos t "+
196 196
         "WHERE t.context_id=c.id "+
@@ -198,23 +198,23 @@ def context_total_actions_data
198 198
         "GROUP BY c.name, c.id "+
199 199
         "ORDER BY total DESC"
200 200
     )
201  
-    @sum = @all_actions_per_context.inject(0){|sum, apc| sum += apc['total'].to_i }
  201
+    @sum = all_actions_per_context.inject(0){|sum, apc| sum += apc['total'].to_i }
202 202
     
203 203
     pie_cutoff=10
204  
-    size = [@all_actions_per_context.size, pie_cutoff].min
  204
+    size = [all_actions_per_context.size, pie_cutoff].min
205 205
     
206 206
     # explicitely copy contents of hash to avoid ending up with two arrays pointing to same hashes
207 207
     @actions_per_context = Array.new(size){|i| {
208  
-      'name' => @all_actions_per_context[i][:name],
209  
-      'total' => @all_actions_per_context[i][:total].to_i,
210  
-      'id' => @all_actions_per_context[i][:id]
  208
+      'name' => all_actions_per_context[i][:name],
  209
+      'total' => all_actions_per_context[i][:total].to_i,
  210
+      'id' => all_actions_per_context[i][:id]
211 211
       } }
212 212
 
213 213
     if size==pie_cutoff
214 214
       @actions_per_context[size-1]['name']=t('stats.other_actions_label')
215 215
       @actions_per_context[size-1]['total']=@actions_per_context[size-1]['total']
216 216
       @actions_per_context[size-1]['id']=-1
217  
-      size.upto(@all_actions_per_context.size-1){ |i| @actions_per_context[size-1]['total']+=(@all_actions_per_context[i]['total'].to_i) }
  217
+      size.upto(all_actions_per_context.size-1){ |i| @actions_per_context[size-1]['total']+=(all_actions_per_context[i]['total'].to_i) }
218 218
     end
219 219
     
220 220
     @truncate_chars = 15
@@ -227,7 +227,7 @@ def context_running_actions_data
227 227
     #
228 228
     # Went from GROUP BY c.id to c.name for compatibility with postgresql. Since
229 229
     # the name is forced to be unique, this should work.
230  
-    @all_actions_per_context = current_user.contexts.find_by_sql(
  230
+    all_actions_per_context = current_user.contexts.find_by_sql(
231 231
       "SELECT c.name AS name, c.id as id, count(*) AS total "+
232 232
         "FROM contexts c, todos t "+
233 233
         "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
235 235
         "GROUP BY c.name, c.id "+
236 236
         "ORDER BY total DESC"
237 237
     )
238  
-    @sum = @all_actions_per_context.inject(0){|sum, apc| sum += apc['total'].to_i }
  238
+    @sum = all_actions_per_context.inject(0){|sum, apc| sum += apc['total'].to_i }
239 239
 
240 240
     pie_cutoff=10
241  
-    size = [@all_actions_per_context.size, pie_cutoff].min
  241
+    size = [all_actions_per_context.size, pie_cutoff].min
242 242
 
243 243
     # explicitely copy contents of hash to avoid ending up with two arrays pointing to same hashes
244 244
     @actions_per_context = Array.new(size){|i| {
245  
-      'name' => @all_actions_per_context[i][:name],
246  
-      'total' => @all_actions_per_context[i][:total].to_i,
247  
-      'id' => @all_actions_per_context[i][:id]
  245
+      'name' => all_actions_per_context[i][:name],
  246
+      'total' => all_actions_per_context[i][:total].to_i,
  247
+      'id' => all_actions_per_context[i][:id]
248 248
       } }
249 249
 
250 250
     if size==pie_cutoff
251 251
       @actions_per_context[size-1]['name']=t('stats.other_actions_label')
252 252
       @actions_per_context[size-1]['total']=@actions_per_context[size-1]['total']
253 253
       @actions_per_context[size-1]['id']=-1
254  
-      (size).upto(@all_actions_per_context.size()-1){|i| @actions_per_context[size-1]['total']+=@all_actions_per_context[i]['total'].to_i }
  254
+      (size).upto(all_actions_per_context.size()-1){|i| @actions_per_context[size-1]['total']+=all_actions_per_context[i]['total'].to_i }
255 255
     end
256 256
 
257 257
     @truncate_chars = 15
@@ -408,7 +408,6 @@ def done
408 408
 
409 409
   private
410 410
 
411  
-
412 411
   def get_unique_tags_of_user
413 412
     tag_ids = current_user.todos.find_by_sql([
414 413
         "SELECT DISTINCT tags.id as id "+

0 notes on commit f9bd923

Please sign in to comment.
Something went wrong with that request. Please try again.