Skip to content

Commit

Permalink
fix Performance/ReverseEach issue
Browse files Browse the repository at this point in the history
Change-Id: I939e883124ebcd67d57febc7dde6336db6277f62
fixes: CNVS-20009
Reviewed-on: https://gerrit.instructure.com/52893
Tested-by: Jenkins
Reviewed-by: Cody Cutrer <[email protected]>
Product-Review: Strand McCutchen <[email protected]>
QA-Review: Strand McCutchen <[email protected]>
  • Loading branch information
Strand McCutchen committed Apr 27, 2015
1 parent 1a24af8 commit 04cb518
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/controllers/lti/ims/tool_setting_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def tool_setting_json(tool_setting, bubble)
elsif bubble == 'distinct' && request.headers['accept'].include?('application/vnd.ims.lti.v2.toolsettings.simple+json')
@content_type = 'application/vnd.ims.lti.v2.toolsettings.simple+json'
custom = {}
graph.reverse.each { |tool_setting| custom.merge!(tool_setting.custom) }
graph.reverse_each { |tool_setting| custom.merge!(tool_setting.custom) }
custom
end
else
Expand Down
2 changes: 1 addition & 1 deletion app/models/account/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def self.included(klass)
# otherwise use the last explicitly set value
def calculate_inherited_setting(setting)
inherited_hash = {:locked => false, :value => self.class.account_settings_options[setting][:default]}
self.account_chain.reverse.each do |acc|
self.account_chain.reverse_each do |acc|
current_hash = acc.settings[setting]
next if current_hash.nil?

Expand Down
2 changes: 1 addition & 1 deletion app/models/grading_standard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def destroy

def grading_scheme
res = {}
self.data.sort_by{|_, lower_bound| lower_bound}.reverse.each do |grade_name, lower_bound|
self.data.sort_by{|_, lower_bound| lower_bound}.reverse_each do |grade_name, lower_bound|
res[grade_name] = lower_bound.to_f
end
res
Expand Down
2 changes: 1 addition & 1 deletion app/models/quizzes/quiz_question_data_fixer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def self.is_valid_data(data)
end

def self.find_good_data(aq)
aq.versions.sort_by { |v| v.number }.reverse.each do |version|
aq.versions.sort_by { |v| v.number }.reverse_each do |version|
data = version.model.question_data
return data if is_valid_data(data)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/quizzes/quiz_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def scores_for_versions(exclude_version_id)
scores[attempt] = self.score if self.score

# only most recent version for each attempt - some have regraded a version
versions.sort_by(&:number).reverse.each do |ver|
versions.sort_by(&:number).reverse_each do |ver|
scores[ver.model.attempt] ||= ver.model.score || 0.0
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def check_for_media_object
def submission_history
res = []
last_submitted_at = nil
self.versions.sort_by(&:created_at).reverse.each do |version|
self.versions.sort_by(&:created_at).reverse_each do |version|
model = version.model
if model.submitted_at && last_submitted_at.to_i != model.submitted_at.to_i
res << model
Expand Down
2 changes: 1 addition & 1 deletion gems/canvas_panda_pub/lib/canvas_panda_pub/async_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def run_thread
# future flexibility for adding more modes (like pushing all updates,
# instead of just the most recent).
seen_channels = Set.new
work.reverse.each do |ary|
work.reverse_each do |ary|
if seen_channels.include? ary[0]
ary[2] = false
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def sanitize_html!(node, remove_extraneous_nodes=false)
child.remove
end

node.children.reverse.each do |child|
node.children.reverse_each do |child|
break unless child.text? && child.text =~ /\A\s+\z/ || child.element? && child.name.downcase == 'br'
child.remove
end
Expand Down
2 changes: 1 addition & 1 deletion lib/api/v1/avatar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def avatars_json_for_user(user, includes={})
:type => 'gravatar',
:alt => 'gravatar pic'
})
user.profile_pics_folder.active_file_attachments({:include => :thumbnail}).select{|a| a.content_type.match(/\Aimage\//) && a.thumbnail}.sort_by(&:id).reverse.each do |image|
user.profile_pics_folder.active_file_attachments({:include => :thumbnail}).select{|a| a.content_type.match(/\Aimage\//) && a.thumbnail}.sort_by(&:id).reverse_each do |image|
avatars << avatar_json(user, image, {
:type => 'attachment',
:alt => image.display_name,
Expand Down
2 changes: 1 addition & 1 deletion lib/gradebook_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def parse!
submission['original_grade'].to_s == submission['grade'] || (submission['original_grade'].blank? && submission['grade'].blank?)
end
end
indexes_to_delete.reverse.each do |idx|
indexes_to_delete.reverse_each do |idx|
@assignments.delete_at(idx)
@students.each do |student|
student.gradebook_importer_submissions.delete_at(idx)
Expand Down
2 changes: 1 addition & 1 deletion spec/migrations/remove_multiple_root_folders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_root_folder_name(context)
subfolders = subfolders.map(&:sub_folders).flatten
folders.concat(subfolders)
end
folders.reverse.each { |f| Folder.where(id: f).delete_all }
folders.reverse_each { |f| Folder.where(id: f).delete_all }
c.enrollment_terms.scoped.delete_all if c.is_a?(Account)
c.course_account_associations.scoped.delete_all if c.is_a?(Course)
c.delete
Expand Down

0 comments on commit 04cb518

Please sign in to comment.