Merge pull request from akshaymohite/optimization-fixes

Not initializing variable for looping if unused in loop
This commit is contained in:
Sam 2014-08-18 14:42:52 +10:00
commit 8737ffb272
15 changed files with 21 additions and 21 deletions

@ -48,7 +48,7 @@ class Admin::EmailController < Admin::AdminController
def delivery_settings def delivery_settings
action_mailer_settings action_mailer_settings
.reject { |k, v| k == :password } .reject { |k, _| k == :password }
.map { |k, v| { name: k, value: v }} .map { |k, v| { name: k, value: v }}
end end

@ -9,7 +9,7 @@ module Jobs
# Retrieve a header regardless of case sensitivity # Retrieve a header regardless of case sensitivity
def self.header_for(head, name) def self.header_for(head, name)
header = head.headers.detect do |k, v| header = head.headers.detect do |k, _|
name == k.downcase name == k.downcase
end end
header[1] if header header[1] if header
@ -65,7 +65,7 @@ module Jobs
return "" unless uri return "" unless uri
result = "" result = ""
streamer = lambda do |chunk, remaining_bytes, total_bytes| streamer = lambda do |chunk, _, _|
result << chunk result << chunk
# Using exceptions for flow control is really bad, but there really seems to # Using exceptions for flow control is really bad, but there really seems to

@ -206,7 +206,7 @@ class Post < ActiveRecord::Base
def has_host_spam? def has_host_spam?
return false if acting_user.present? && acting_user.has_trust_level?(:basic) return false if acting_user.present? && acting_user.has_trust_level?(:basic)
total_hosts_usage.each do |host, count| total_hosts_usage.each do |_, count|
return true if count >= SiteSetting.newuser_spam_host_threshold return true if count >= SiteSetting.newuser_spam_host_threshold
end end

@ -11,7 +11,7 @@ class PostAnalyzer
def cook(*args) def cook(*args)
cooked = PrettyText.cook(*args) cooked = PrettyText.cook(*args)
result = Oneboxer.apply(cooked) do |url, elem| result = Oneboxer.apply(cooked) do |url, _|
Oneboxer.invalidate(url) if args.last[:invalidate_oneboxes] Oneboxer.invalidate(url) if args.last[:invalidate_oneboxes]
Oneboxer.cached_onebox url Oneboxer.cached_onebox url
end end

@ -105,8 +105,8 @@ class TopicLink < ActiveRecord::Base
PrettyText PrettyText
.extract_links(post.cooked) .extract_links(post.cooked)
.map{|u| [u, URI.parse(u.url)] rescue nil} .map{|u| [u, URI.parse(u.url)] rescue nil}
.reject{|u,p| p.nil?} .reject{|_, p| p.nil?}
.uniq{|u,p| p} .uniq{|_, p| p}
.each do |link, parsed| .each do |link, parsed|
begin begin

@ -161,7 +161,7 @@ LEFT JOIN categories c on c.id = t.category_id
# TODO there are conditions when this is called and user_id was already rolled back and is invalid. # TODO there are conditions when this is called and user_id was already rolled back and is invalid.
# protect against dupes, for some reason this is failing in some cases # protect against dupes, for some reason this is failing in some cases
action = self.find_by(hash.select { |k, v| required_parameters.include?(k) }) action = self.find_by(hash.select { |k, _| required_parameters.include?(k) })
return action if action return action if action
action = self.new(hash) action = self.new(hash)

@ -38,7 +38,7 @@ Discourse::Application.configure do
settings[:openssl_verify_mode] = GlobalSetting.smtp_openssl_verify_mode if GlobalSetting.smtp_openssl_verify_mode settings[:openssl_verify_mode] = GlobalSetting.smtp_openssl_verify_mode if GlobalSetting.smtp_openssl_verify_mode
config.action_mailer.smtp_settings = settings.reject{|x,y| y.nil?} config.action_mailer.smtp_settings = settings.reject{|_, y| y.nil?}
else else
config.action_mailer.delivery_method = :sendmail config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {arguments: '-i'} config.action_mailer.sendmail_settings = {arguments: '-i'}

@ -18,7 +18,7 @@ class AdminUserIndexQuery
end end
def filter_by_trust def filter_by_trust
levels = trust_levels.map { |key, value| key.to_s } levels = trust_levels.map { |key, _| key.to_s }
if levels.include?(params[:query]) if levels.include?(params[:query])
@query.where('trust_level = ?', trust_levels[params[:query].to_sym]) @query.where('trust_level = ?', trust_levels[params[:query].to_sym])
end end

@ -63,7 +63,7 @@ class Autospec::Manager
def ensure_all_specs_will_run def ensure_all_specs_will_run
puts "@@@@@@@@@@@@ ensure_all_specs_will_run" if @debug puts "@@@@@@@@@@@@ ensure_all_specs_will_run" if @debug
@runners.each do |runner| @runners.each do |runner|
@queue << ['spec', 'spec', runner] unless @queue.any? { |f, s, r| s == "spec" && r == runner } @queue << ['spec', 'spec', runner] unless @queue.any? { |_, s, r| s == "spec" && r == runner }
end end
end end
@ -152,7 +152,7 @@ class Autospec::Manager
end end
Thread.start do Thread.start do
Listen.to('.', options) do |modified, added, removed| Listen.to('.', options) do |modified, added, _|
process_change([modified, added].flatten.compact) process_change([modified, added].flatten.compact)
end end
end end
@ -187,7 +187,7 @@ class Autospec::Manager
end end
end end
# special watcher for styles/templates # special watcher for styles/templates
Autospec::ReloadCss::WATCHERS.each do |k,v| Autospec::ReloadCss::WATCHERS.each do |k, _|
matches = [] matches = []
matches << file if k.match(file) matches << file if k.match(file)
Autospec::ReloadCss.run_on_change(matches) if matches.present? Autospec::ReloadCss.run_on_change(matches) if matches.present?
@ -220,7 +220,7 @@ class Autospec::Manager
puts "@@@@@@@@@@@@ #{@queue}" if @debug puts "@@@@@@@@@@@@ #{@queue}" if @debug
specs.each do |file, spec, runner| specs.each do |file, spec, runner|
# make sure there's no other instance of this spec in the queue # make sure there's no other instance of this spec in the queue
@queue.delete_if { |f, s, r| s.strip == spec.strip && r == runner } @queue.delete_if { |_, s, r| s.strip == spec.strip && r == runner }
# deal with focused specs # deal with focused specs
if @queue.first && @queue.first[0] == "focus" if @queue.first && @queue.first[0] == "focus"
focus = @queue.shift focus = @queue.shift

@ -121,7 +121,7 @@ module Export
end end
def sidekiq_has_running_jobs? def sidekiq_has_running_jobs?
Sidekiq::Workers.new.each do |process_id, thread_id, worker| Sidekiq::Workers.new.each do |_, _, worker|
payload = worker.try(:payload) payload = worker.try(:payload)
return true if payload.try(:all_sites) return true if payload.try(:all_sites)
return true if payload.try(:current_site_id) == @current_db return true if payload.try(:current_site_id) == @current_db

@ -142,7 +142,7 @@ module Import
end end
def sidekiq_has_running_jobs? def sidekiq_has_running_jobs?
Sidekiq::Workers.new.each do |process_id, thread_id, worker| Sidekiq::Workers.new.each do |_, _, worker|
payload = worker.try(:payload) payload = worker.try(:payload)
return true if payload.try(:all_sites) return true if payload.try(:all_sites)
return true if payload.try(:current_site_id) == @current_db return true if payload.try(:current_site_id) == @current_db

@ -84,7 +84,7 @@ module Middleware
status,headers,response = result status,headers,response = result
if status == 200 && cache_duration if status == 200 && cache_duration
headers_stripped = headers.dup.delete_if{|k,v| ["Set-Cookie","X-MiniProfiler-Ids"].include? k} headers_stripped = headers.dup.delete_if{|k, _| ["Set-Cookie","X-MiniProfiler-Ids"].include? k}
parts = [] parts = []
response.each do |part| response.each do |part|
parts << part parts << part

@ -139,7 +139,7 @@ class PostDestroyer
public_post_actions = PostAction.publics.where(post_id: @post.id) public_post_actions = PostAction.publics.where(post_id: @post.id)
public_post_actions.each { |pa| pa.trash!(@user) } public_post_actions.each { |pa| pa.trash!(@user) }
f = PostActionType.public_types.map { |k,v| ["#{k}_count", 0] } f = PostActionType.public_types.map { |k, _| ["#{k}_count", 0] }
Post.with_deleted.where(id: @post.id).update_all(Hash[*f.flatten]) Post.with_deleted.where(id: @post.id).update_all(Hash[*f.flatten])
end end

@ -105,7 +105,7 @@ module SiteSettingExtension
def settings_hash def settings_hash
result = {} result = {}
@defaults.each do |s, v| @defaults.each do |s, _|
result[s] = send(s).to_s result[s] = send(s).to_s
end end
result result
@ -124,7 +124,7 @@ module SiteSettingExtension
# Retrieve all settings # Retrieve all settings
def all_settings(include_hidden=false) def all_settings(include_hidden=false)
@defaults @defaults
.reject{|s, v| hidden_settings.include?(s) || include_hidden} .reject{|s, _| hidden_settings.include?(s) || include_hidden}
.map do |s, v| .map do |s, v|
value = send(s) value = send(s)
type = types[get_data_type(s, value)] type = types[get_data_type(s, value)]

@ -23,7 +23,7 @@ def profile_allocations(name)
initial_size = ObjectSpace.count_objects initial_size = ObjectSpace.count_objects
yield yield
changes = ObjectSpace.count_objects changes = ObjectSpace.count_objects
changes.each do |k,v| changes.each do |k, _|
changes[k] -= initial_size[k] changes[k] -= initial_size[k]
end end
puts "#{name} changes" puts "#{name} changes"