mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 05:01:14 +08:00
Add rubocop to our build. (#5004)
This commit is contained in:
@ -45,7 +45,6 @@ module Jobs
|
||||
title: I18n.t('performance_report.initial_topic_title'),
|
||||
skip_validations: true)
|
||||
|
||||
|
||||
unless post && post.topic_id
|
||||
raise StandardError, "Could not create or retrieve performance report topic id"
|
||||
end
|
||||
|
@ -2,7 +2,6 @@ class LogAnalyzer
|
||||
|
||||
class LineParser
|
||||
|
||||
|
||||
# log_format log_discourse '[$time_local] "$http_host" $remote_addr "$request" "$http_user_agent" "$sent_http_x_discourse_route" $status $bytes_sent "$http_referer" $upstream_response_time $request_time "$sent_http_x_discourse_username"';
|
||||
|
||||
attr_accessor :time, :ip_address, :url, :route, :user_agent, :rails_duration, :total_duration,
|
||||
@ -69,8 +68,8 @@ class LogAnalyzer
|
||||
@aggregate_type = :duration
|
||||
end
|
||||
|
||||
def add(id, duration, aggregate=nil)
|
||||
ary = (@data[id] ||= [0,0])
|
||||
def add(id, duration, aggregate = nil)
|
||||
ary = (@data[id] ||= [0, 0])
|
||||
ary[0] += duration
|
||||
ary[1] += 1
|
||||
unless aggregate.nil?
|
||||
@ -83,8 +82,8 @@ class LogAnalyzer
|
||||
end
|
||||
end
|
||||
|
||||
def top(n, aggregator_formatter=nil)
|
||||
@data.sort{|a,b| b[1][0] <=> a[1][0]}.first(n).map do |metric, ary|
|
||||
def top(n, aggregator_formatter = nil)
|
||||
@data.sort { |a, b| b[1][0] <=> a[1][0] }.first(n).map do |metric, ary|
|
||||
metric = metric.to_s
|
||||
metric = "[empty]" if metric.length == 0
|
||||
result = [metric, ary[0], ary[1]]
|
||||
@ -93,7 +92,7 @@ class LogAnalyzer
|
||||
if aggregator_formatter
|
||||
result.push aggregator_formatter.call(ary[2], ary[0], ary[1])
|
||||
else
|
||||
result.push ary[2].sort{|a,b| b[1] <=> a[1]}.first(5).map{|k,v|
|
||||
result.push ary[2].sort { |a, b| b[1] <=> a[1] }.first(5).map { |k, v|
|
||||
v = "%.2f" % v if Float === v
|
||||
"#{k}(#{v})"}.join(" ")
|
||||
end
|
||||
@ -104,7 +103,7 @@ class LogAnalyzer
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(filenames, args={})
|
||||
def initialize(filenames, args = {})
|
||||
@filenames = filenames
|
||||
@ip_to_rails_duration = Aggeregator.new
|
||||
@username_to_rails_duration = Aggeregator.new
|
||||
@ -148,7 +147,7 @@ class LogAnalyzer
|
||||
|
||||
@url_to_rails_duration.add(parsed.url, parsed.rails_duration)
|
||||
|
||||
@status_404_to_count.add(parsed.url,1) if parsed.status == "404"
|
||||
@status_404_to_count.add(parsed.url, 1) if parsed.status == "404"
|
||||
end
|
||||
end
|
||||
self
|
||||
|
@ -30,7 +30,7 @@ def top(cols, aggregator, count, aggregator_formatter = nil)
|
||||
|
||||
col_just = []
|
||||
|
||||
col_widths = map_with_index(cols) do |name,idx|
|
||||
col_widths = map_with_index(cols) do |name, idx|
|
||||
max_width = name.length
|
||||
|
||||
if cols[idx].respond_to? :align
|
||||
@ -46,14 +46,14 @@ def top(cols, aggregator, count, aggregator_formatter = nil)
|
||||
row[idx] = row[idx].to_s
|
||||
max_width = row[idx].length if row[idx].length > max_width
|
||||
end
|
||||
[max_width,80].min
|
||||
[max_width, 80].min
|
||||
end
|
||||
|
||||
puts(map_with_index(cols) do |name,idx|
|
||||
puts(map_with_index(cols) do |name, idx|
|
||||
name.ljust(col_widths[idx])
|
||||
end.join(" "))
|
||||
|
||||
puts(map_with_index(cols) do |name,idx|
|
||||
puts(map_with_index(cols) do |name, idx|
|
||||
("-" * name.length).ljust(col_widths[idx])
|
||||
end.join(" "))
|
||||
|
||||
@ -102,7 +102,7 @@ end
|
||||
puts
|
||||
puts "Analyzed: #{analyzer.filenames.join(",")} on #{`hostname`}"
|
||||
if limit
|
||||
puts "Limited to #{DateTime.now - (limit.to_f / (60*24.0))} - #{DateTime.now}"
|
||||
puts "Limited to #{DateTime.now - (limit.to_f / (60 * 24.0))} - #{DateTime.now}"
|
||||
end
|
||||
puts SPACER
|
||||
puts "#{analyzer.from_time} - #{analyzer.to_time}"
|
||||
@ -121,7 +121,7 @@ puts SPACER
|
||||
puts
|
||||
puts "Top 100 routes by Server Load"
|
||||
puts
|
||||
top(["Route", "Duration", "Reqs", Column.new("Mobile", :rjust)], analyzer.route_to_rails_duration, 100, lambda{
|
||||
top(["Route", "Duration", "Reqs", Column.new("Mobile", :rjust)], analyzer.route_to_rails_duration, 100, lambda {
|
||||
|hash, name, total|
|
||||
"#{hash["mobile"] || 0} (#{"%.2f" % (((hash["mobile"] || 0) / (total + 0.0)) * 100)})%"}
|
||||
)
|
||||
|
Reference in New Issue
Block a user