From 5f92de8edef02a0d8e67193b8634423731a8923c Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 7 Jun 2016 16:49:22 +0800 Subject: [PATCH] Remove unnecessary for loop. --- plugins/poll/lib/polls_updater.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/poll/lib/polls_updater.rb b/plugins/poll/lib/polls_updater.rb index f1c6824e2..817071b7a 100644 --- a/plugins/poll/lib/polls_updater.rb +++ b/plugins/poll/lib/polls_updater.rb @@ -7,11 +7,11 @@ module DiscoursePoll previous_polls = post.custom_fields[DiscoursePoll::POLLS_CUSTOM_FIELD] || {} # extract options - current_options = extract_option_ids(polls) - previous_options = extract_option_ids(previous_polls) + current_option_ids = extract_option_ids(polls) + previous_option_ids = extract_option_ids(previous_polls) # are the polls different? - if polls_updated?(polls, previous_polls) || (current_options != previous_options) + if polls_updated?(polls, previous_polls) || (current_option_ids != previous_option_ids) has_votes = total_votes(previous_polls) > 0 # outside of the 5-minute edit window? @@ -52,12 +52,12 @@ module DiscoursePoll polls[poll_name]["voters"] = previous_polls[poll_name]["voters"] polls[poll_name]["anonymous_voters"] = previous_polls[poll_name]["anonymous_voters"] if previous_polls[poll_name].has_key?("anonymous_voters") - for o in 0...polls[poll_name]["options"].size - current_option = polls[poll_name]["options"][o] - previous_option = previous_polls[poll_name]["options"][o] + previous_options = previous_polls[poll_name]["options"] - current_option["votes"] = previous_option["votes"] - current_option["anonymous_votes"] = previous_option["anonymous_votes"] if previous_option.has_key?("anonymous_votes") + polls[poll_name]["options"].each_with_index do |option, index| + previous_option = previous_options[index] + option["votes"] = previous_option["votes"] + option["anonymous_votes"] = previous_option["anonymous_votes"] if previous_option.has_key?("anonymous_votes") end end