sql-logging 3.0.8 → 3.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75e58e5f101ae2526faab84ad37755deb83fb59b
4
+ data.tar.gz: 02d77d4c791c74056d557934c598afa32cb29d3d
5
+ SHA512:
6
+ metadata.gz: 460b73d5ea7b42e0dcd296d8eabe3c18e5d9bf56850f500d2a41461c11e151e879621ece3cea4dda095beca6314d0f6ea41b0ae362a575172da70c12c53cc647
7
+ data.tar.gz: 469b866fbde399773894c8469229ed15d94c6dc06526588f96da2605d033b3ea8469cecac2bb55a811183100ae3ba7b5e0670213f280008f188f6c120d7760ba
@@ -0,0 +1,21 @@
1
+ require 'active_record/connection_adapters/abstract/query_cache'
2
+
3
+ module ActiveRecord::ConnectionAdapters::QueryCache
4
+ private
5
+
6
+ def cache_sql_with_sql_logging(sql, binds, &blk)
7
+ if @query_cache.has_key?(sql)
8
+ rows = nil
9
+ elapsed = Benchmark.measure do
10
+ rows = cache_sql_without_sql_logging(sql, binds, &blk)
11
+ end
12
+ msec = elapsed.real * 1000
13
+ SqlLogging::Statistics.record_query(sql, "CACHE", msec, rows)
14
+ rows
15
+ else
16
+ cache_sql_without_sql_logging(sql, binds, &blk)
17
+ end
18
+ end
19
+
20
+ alias_method_chain :cache_sql, :sql_logging
21
+ end
@@ -0,0 +1,15 @@
1
+ require 'active_record/connection_adapters/pedant_mysql2_adapter'
2
+
3
+ class ActiveRecord::ConnectionAdapters::Mysql2Adapter
4
+ def select_with_sql_logging(sql, *args)
5
+ rows = nil
6
+ elapsed = Benchmark.measure do
7
+ rows = select_without_sql_logging(sql, *args)
8
+ end
9
+ msec = elapsed.real * 1000
10
+ SqlLogging::Statistics.record_query(sql, args.first, msec, rows)
11
+ rows
12
+ end
13
+
14
+ alias_method_chain :select, :sql_logging
15
+ end
@@ -7,6 +7,7 @@ module SqlLogging
7
7
  initializer 'sql_logging.load_adapter_extensions' do
8
8
  ActiveSupport.on_load(:active_record, :after => 'active_record.initialize_database') do
9
9
  adapter = ActiveRecord::Base.configurations[Rails.env]['adapter']
10
+ require "sql-logging/adapters/cache_extension"
10
11
  begin
11
12
  require "sql-logging/adapters/#{adapter}"
12
13
  rescue LoadError => e
@@ -12,6 +12,7 @@ module SqlLogging
12
12
  @@show_sql_backtrace = true
13
13
  @@show_top_sql_queries = :total_time
14
14
  @@top_sql_queries = 10
15
+ @@backtrace_cleaner = nil
15
16
 
16
17
  cattr_accessor :show_sql_backtrace, :top_sql_queries
17
18
 
@@ -34,10 +35,15 @@ module SqlLogging
34
35
  @@queries = @@bytes = @@rows = 0
35
36
  @@top_queries = {}
36
37
  end
37
-
38
- @@backtrace_cleaner = Rails.backtrace_cleaner.dup
39
- @@backtrace_cleaner.add_silencer { |line| line =~ %r{sql-logging/lib} }
40
-
38
+
39
+ def self.backtrace_cleaner
40
+ unless @@backtrace_cleaner
41
+ @@backtrace_cleaner = Rails.backtrace_cleaner.dup
42
+ @@backtrace_cleaner.add_silencer { |line| line =~ %r{sql-logging/lib} }
43
+ end
44
+ @@backtrace_cleaner
45
+ end
46
+
41
47
  def self.record_query(sql, name, msec, result)
42
48
  unless name.blank? || name =~ / Columns$/ || name == :skip_logging
43
49
  bytes = 0
@@ -53,6 +59,8 @@ module SqlLogging
53
59
  ntuples = 0
54
60
  if result.respond_to?(:length)
55
61
  ntuples = result.length
62
+ elsif result.respond_to?(:count)
63
+ ntuples = result.count
56
64
  elsif result.respond_to?(:num_rows)
57
65
  ntuples = result.num_rows
58
66
  elsif result.respond_to?(:ntuples)
@@ -64,7 +72,7 @@ module SqlLogging
64
72
  @@rows += ntuples
65
73
  @@bytes += bytes
66
74
 
67
- backtrace = @@backtrace_cleaner.clean(caller).join("\n ")
75
+ backtrace = backtrace_cleaner.clean(caller).join("\n ")
68
76
  unless @@show_top_sql_queries == false
69
77
  key = "#{name}:#{backtrace}"
70
78
  unless query = @@top_queries[key]
@@ -74,34 +82,28 @@ module SqlLogging
74
82
  query.log_query(ntuples || 0, bytes || 0, msec)
75
83
  end
76
84
 
77
- Rails.logger.debug " #{helper.pluralize(ntuples, 'row')}, #{helper.number_to_human_size(bytes)}"
85
+ Rails.logger.debug " #{ntuples} rows, #{bytes} bytes"
78
86
  Rails.logger.debug " #{backtrace}" if @@show_sql_backtrace
79
87
  end
80
88
  end
81
89
 
82
90
  def self.log_report
83
- Rails.logger.debug "SQL Logging: #{helper.pluralize(@@queries, 'statement')} executed, returning #{helper.number_to_human_size(@@bytes)}"
91
+ Rails.logger.debug "SQL Logging: #{@@queries} statements executed, returning #{@@bytes} bytes"
84
92
 
85
93
  unless @@show_top_sql_queries == false || @@top_queries.empty?
86
94
  Rails.logger.debug "Top #{@@top_sql_queries} SQL executions:"
87
95
  sorted_keys = @@top_queries.keys.sort_by { |k| @@top_queries[k][@@show_top_sql_queries] }.reverse
88
96
  sorted_keys.slice(0..@@top_sql_queries).each do |key|
89
97
  query = @@top_queries[key]
90
- Rails.logger.debug " Executed #{helper.pluralize(query.queries, 'time')} in #{'%.1f' % query.total_time}ms " +
98
+ Rails.logger.debug " Executed #{query.queries} times in #{'%.1f' % query.total_time}ms " +
91
99
  "(#{'%.1f' % query.min_time}/#{'%.1f' % query.median_time}/#{'%.1f' % query.max_time}ms min/median/max), " +
92
- "returning #{helper.pluralize(query.rows, 'row')} " +
93
- "(#{helper.number_to_human_size(query.bytes)}):\n" +
100
+ "returning #{query.rows} rows" +
101
+ "(#{query.bytes} bytes):\n" +
94
102
  " #{query.name}\n" +
95
103
  " First exec was: #{query.sql}\n" +
96
104
  " #{query.backtrace}"
97
105
  end
98
106
  end
99
107
  end
100
-
101
- protected
102
-
103
- def self.helper
104
- Helper.instance
105
- end
106
108
  end
107
109
  end
@@ -1,3 +1,3 @@
1
1
  module SqlLogging
2
- VERSION = '3.0.8'
2
+ VERSION = '3.0.9'
3
3
  end
metadata CHANGED
@@ -1,49 +1,52 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sql-logging
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease:
6
- segments:
7
- - 3
8
- - 0
9
- - 8
10
- version: 3.0.8
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.9
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Steve Madsen
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-05-03 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2015-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: rails
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">"
27
- - !ruby/object:Gem::Version
28
- hash: 7
29
- segments:
30
- - 3
31
- - 0
32
- - 0
33
- version: 3.0.0
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5'
34
23
  type: :runtime
35
- version_requirements: *id001
36
- description: Adds SQL analysis and debugging info to Rails 3 apps.
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5'
33
+ description: |2
34
+ sql-logging adds functionality to Rails to debug query performance.
35
+ SQL triggered by your application includes a stack trace so you can determine
36
+ what code led to it, and a summary is emitted after each request to highlight
37
+ the most expensive queries executed.
37
38
  email: steve@lightyearsoftware.com
38
39
  executables: []
39
-
40
40
  extensions: []
41
-
42
- extra_rdoc_files:
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ files:
43
44
  - README.rdoc
44
- files:
45
+ - lib/sql-logging.rb
46
+ - lib/sql-logging/adapters/cache_extension.rb
45
47
  - lib/sql-logging/adapters/mysql.rb
46
48
  - lib/sql-logging/adapters/mysql2.rb
49
+ - lib/sql-logging/adapters/pedant_mysql2.rb
47
50
  - lib/sql-logging/adapters/postgresql.rb
48
51
  - lib/sql-logging/adapters/sqlite.rb
49
52
  - lib/sql-logging/adapters/sqlite3.rb
@@ -52,40 +55,28 @@ files:
52
55
  - lib/sql-logging/railtie.rb
53
56
  - lib/sql-logging/statistics.rb
54
57
  - lib/sql-logging/version.rb
55
- - lib/sql-logging.rb
56
- - README.rdoc
57
58
  homepage: http://github.com/lightyear/sql-logging
58
- licenses: []
59
-
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
60
62
  post_install_message:
61
63
  rdoc_options: []
62
-
63
- require_paths:
64
+ require_paths:
64
65
  - lib
65
- required_ruby_version: !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
68
  - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
74
- required_rubygems_version: !ruby/object:Gem::Requirement
75
- none: false
76
- requirements:
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
77
73
  - - ">="
78
- - !ruby/object:Gem::Version
79
- hash: 3
80
- segments:
81
- - 0
82
- version: "0"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
83
76
  requirements: []
84
-
85
77
  rubyforge_project:
86
- rubygems_version: 1.8.10
78
+ rubygems_version: 2.2.2
87
79
  signing_key:
88
- specification_version: 3
89
- summary: Adds SQL analysis and debugging info to Rails 3 apps.
80
+ specification_version: 4
81
+ summary: Adds SQL analysis and debugging info to Rails 3+ apps.
90
82
  test_files: []
91
-