mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-21 17:50:13 +01:00
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.
This commit is contained in:
parent
d9f4226fbe
commit
f9bd923205
1 changed files with 14 additions and 15 deletions
|
|
@ -190,7 +190,7 @@ class StatsController < ApplicationController
|
||||||
# get total action count per context Went from GROUP BY c.id to c.name for
|
# 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
|
# compatibility with postgresql. Since the name is forced to be unique, this
|
||||||
# should work.
|
# 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 "+
|
"SELECT c.name AS name, c.id as id, count(*) AS total "+
|
||||||
"FROM contexts c, todos t "+
|
"FROM contexts c, todos t "+
|
||||||
"WHERE t.context_id=c.id "+
|
"WHERE t.context_id=c.id "+
|
||||||
|
|
@ -198,23 +198,23 @@ class StatsController < ApplicationController
|
||||||
"GROUP BY c.name, c.id "+
|
"GROUP BY c.name, c.id "+
|
||||||
"ORDER BY total DESC"
|
"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
|
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
|
# explicitely copy contents of hash to avoid ending up with two arrays pointing to same hashes
|
||||||
@actions_per_context = Array.new(size){|i| {
|
@actions_per_context = Array.new(size){|i| {
|
||||||
'name' => @all_actions_per_context[i][:name],
|
'name' => all_actions_per_context[i][:name],
|
||||||
'total' => @all_actions_per_context[i][:total].to_i,
|
'total' => all_actions_per_context[i][:total].to_i,
|
||||||
'id' => @all_actions_per_context[i][:id]
|
'id' => all_actions_per_context[i][:id]
|
||||||
} }
|
} }
|
||||||
|
|
||||||
if size==pie_cutoff
|
if size==pie_cutoff
|
||||||
@actions_per_context[size-1]['name']=t('stats.other_actions_label')
|
@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]['total']=@actions_per_context[size-1]['total']
|
||||||
@actions_per_context[size-1]['id']=-1
|
@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
|
end
|
||||||
|
|
||||||
@truncate_chars = 15
|
@truncate_chars = 15
|
||||||
|
|
@ -227,7 +227,7 @@ class StatsController < ApplicationController
|
||||||
#
|
#
|
||||||
# Went from GROUP BY c.id to c.name for compatibility with postgresql. Since
|
# Went from GROUP BY c.id to c.name for compatibility with postgresql. Since
|
||||||
# the name is forced to be unique, this should work.
|
# 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 "+
|
"SELECT c.name AS name, c.id as id, count(*) AS total "+
|
||||||
"FROM contexts c, todos t "+
|
"FROM contexts c, todos t "+
|
||||||
"WHERE t.context_id=c.id AND t.completed_at IS NULL AND NOT c.hide "+
|
"WHERE t.context_id=c.id AND t.completed_at IS NULL AND NOT c.hide "+
|
||||||
|
|
@ -235,23 +235,23 @@ class StatsController < ApplicationController
|
||||||
"GROUP BY c.name, c.id "+
|
"GROUP BY c.name, c.id "+
|
||||||
"ORDER BY total DESC"
|
"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
|
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
|
# explicitely copy contents of hash to avoid ending up with two arrays pointing to same hashes
|
||||||
@actions_per_context = Array.new(size){|i| {
|
@actions_per_context = Array.new(size){|i| {
|
||||||
'name' => @all_actions_per_context[i][:name],
|
'name' => all_actions_per_context[i][:name],
|
||||||
'total' => @all_actions_per_context[i][:total].to_i,
|
'total' => all_actions_per_context[i][:total].to_i,
|
||||||
'id' => @all_actions_per_context[i][:id]
|
'id' => all_actions_per_context[i][:id]
|
||||||
} }
|
} }
|
||||||
|
|
||||||
if size==pie_cutoff
|
if size==pie_cutoff
|
||||||
@actions_per_context[size-1]['name']=t('stats.other_actions_label')
|
@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]['total']=@actions_per_context[size-1]['total']
|
||||||
@actions_per_context[size-1]['id']=-1
|
@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
|
end
|
||||||
|
|
||||||
@truncate_chars = 15
|
@truncate_chars = 15
|
||||||
|
|
@ -408,7 +408,6 @@ class StatsController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
||||||
def get_unique_tags_of_user
|
def get_unique_tags_of_user
|
||||||
tag_ids = current_user.todos.find_by_sql([
|
tag_ids = current_user.todos.find_by_sql([
|
||||||
"SELECT DISTINCT tags.id as id "+
|
"SELECT DISTINCT tags.id as id "+
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue