marginalia 1.7.1 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 652f9d4885b38bec5a45af1fe9a6e2b32b2d0efe
4
- data.tar.gz: 9f11163229b538432b7128497066dd8de3d7f06b
3
+ metadata.gz: d2bf4536bf33fce1b7c806d0b2fec3cbe221b166
4
+ data.tar.gz: ed2d7dfeac456ce8a9f63f5257e63e7d05526f6d
5
5
  SHA512:
6
- metadata.gz: 338835145956ad4a5b83c73f0587d08646d6828377afe51ea6af8e5ec903bd6451c936114fd47fbd7191c8f20a5fba997f66bcc06e550125cb9ed33b230d7ec3
7
- data.tar.gz: 0233a2cb61340a679f96fa9119e9c382121074c3b8874821e96b52952cee4c59c88a6f1efd7a983dbf9527b0e694f31f44dfb83e7ee74079eb40a0564bff5812
6
+ metadata.gz: 255f216a7e47faa1a4d5e36f38a922d6abca36ce2f3a9c3189f2849a50c543237c9be76c1bf8abe9064f1b97d0c9d78379883271405e3e3781359be22ec08ed3
7
+ data.tar.gz: 0983b7a057ecb4cf56cd031572d6f498c8906daf8b7f67b8a5d7a9e7944128d23d27f78b8020d93c52ef5f6670d127e1a1c47da4aee6d96df1a7b0104f65887f
data/README.md CHANGED
@@ -56,6 +56,8 @@ Optionally, you can set the application name shown in the log like so in an init
56
56
  For Rails 3 applications, the name will default to your Rails application name.
57
57
  For Rails 2 applications, "rails" is used as the default application name.
58
58
 
59
+ #### Components
60
+
59
61
  You can also configure the components of the comment that will be appended,
60
62
  by setting `Marginalia::Comment.components`. By default, this is set to:
61
63
 
@@ -100,7 +102,17 @@ With ActiveRecord >= 3.2.19:
100
102
 
101
103
  Pull requests for other included comment components are welcome.
102
104
 
103
- ## Inline query annotations
105
+ #### Prepend comments
106
+
107
+ By default marginalia appends the comments at the end of the query. Certain databases, such as MySQL will truncate
108
+ the query text. This is the case for slow query logs and the results of querying some InnoDB internal tables where the
109
+ length of the query is more than 1024 bytes.
110
+
111
+ In order to not lose the marginalia comments from your logs, you can prepend the comments using this option:
112
+
113
+ Marginalia::Comment.prepend_comment = true
114
+
115
+ #### Inline query annotations
104
116
 
105
117
  In addition to the request or job-level component-based annotations,
106
118
  Marginalia may be used to add inline annotations to specific queries using a
@@ -49,12 +49,21 @@ module Marginalia
49
49
  Marginalia::Comment.update_adapter!(self)
50
50
  comment = Marginalia::Comment.construct_comment
51
51
  if comment.present? && !sql.include?(comment)
52
- sql = "#{sql} /*#{comment}*/"
52
+ sql = if Marginalia::Comment.prepend_comment
53
+ "/*#{comment}*/ #{sql}"
54
+ else
55
+ "#{sql} /*#{comment}*/"
56
+ end
53
57
  end
54
58
  inline_comment = Marginalia::Comment.construct_inline_comment
55
59
  if inline_comment.present? && !sql.include?(inline_comment)
56
- sql = "#{sql} /*#{inline_comment}*/"
60
+ sql = if Marginalia::Comment.prepend_comment
61
+ "/*#{inline_comment}*/ #{sql}"
62
+ else
63
+ "#{sql} /*#{inline_comment}*/"
64
+ end
57
65
  end
66
+
58
67
  sql
59
68
  end
60
69
 
@@ -2,7 +2,7 @@ require 'socket'
2
2
 
3
3
  module Marginalia
4
4
  module Comment
5
- mattr_accessor :components, :lines_to_ignore
5
+ mattr_accessor :components, :lines_to_ignore, :prepend_comment
6
6
  Marginalia::Comment.components ||= [:application, :controller, :action]
7
7
 
8
8
  def self.update!(controller = nil)
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.test_files = `git ls-files -- {test}/*`.split("\n")
9
9
  gem.name = "marginalia"
10
10
  gem.require_paths = ["lib"]
11
- gem.version = "1.7.1"
11
+ gem.version = "1.8.0"
12
12
  gem.license = "MIT"
13
13
 
14
14
  gem.add_runtime_dependency "actionpack", ">= 2.3"
@@ -348,6 +348,15 @@ class MarginaliaTest < MiniTest::Test
348
348
  assert_match %r{select id from posts /\*foo\*/ /\*application:rails\*/$}, @queries.first
349
349
  end
350
350
 
351
+ def test_add_comments_to_beginning_of_query
352
+ Marginalia::Comment.prepend_comment = true
353
+
354
+ ActiveRecord::Base.connection.execute "select id from posts"
355
+ assert_match %r{/\*application:rails\*/ select id from posts$}, @queries.first
356
+ ensure
357
+ Marginalia::Comment.prepend_comment = nil
358
+ end
359
+
351
360
  def teardown
352
361
  Marginalia.application_name = nil
353
362
  Marginalia::Comment.lines_to_ignore = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marginalia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Lorang
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-03-19 00:00:00.000000000 Z
13
+ date: 2019-03-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack