time_bandits 0.13.1 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e14e3f3974575197ad97649241f327dbf69824c354044bde8bd55ff421d9c21a
4
- data.tar.gz: 4115bb4f9820a3227a62d6b4ea66c5f045c59cacb019fd89be71ff9da6b2f790
3
+ metadata.gz: d5b75c63570dfa36709209cb0e1abe7fd8842bc795c7e0c5dd15a285af090bf6
4
+ data.tar.gz: afb24d0ea48efe0ec1505be1550ece1cb31af9c4b1eb5df55b96e2c1898e90b4
5
5
  SHA512:
6
- metadata.gz: abc74cb6ae11bdf9388f8d113a3df89d61e6403cd614ebdd8d73aaa5be84c8a2d9d50d746b57a2eb4079140e1a34c9e1e3c172428e1065d15893ad94e99330b6
7
- data.tar.gz: bd2347a6f49613abd7359524c1a08cb609acf501180b1deeb5b093318b664ff330c7a0bd8b2a577b1dee303d62ea8481162485b704d4f9041000cc58b3dd77a2
6
+ metadata.gz: 05a7d021d2b0242a5289450fa385dc86d6c3e2512c4a331e40a3428d7d5ab19be347544a32bac8df2a1ba726c898a6ba8b51a698312107a5a7730995a45cfacd
7
+ data.tar.gz: 953e21a301535b9384263fd1d686e5dd4eea45ca25bd5b64191f979b6b83dde73e439f38428114e54e6ee83ce7baffc2fa16e7c492cabd070a0dcb29b409a4e3
@@ -13,7 +13,7 @@ jobs:
13
13
 
14
14
  strategy:
15
15
  matrix:
16
- ruby-version: [3.2.0, 3.1.3, 3.0.5, 2.7.7]
16
+ ruby-version: [3.2.2, 3.1.4, 3.0.6, 2.7.8]
17
17
 
18
18
  steps:
19
19
  - uses: actions/checkout@v3
data/Appraisals CHANGED
@@ -1,10 +1,11 @@
1
1
  appraisals = [
2
- "6.0.6",
3
- "6.1.6",
2
+ "6.0.6.1",
3
+ "6.1.7.6",
4
+ "7.0.8",
5
+ "7.1.0"
4
6
  ]
5
7
 
6
8
  appraisals.insert(0, "5.2.8.1") if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.0.0")
7
- appraisals << "7.0.4" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.7.0")
8
9
 
9
10
  appraisals.each do |rails_version|
10
11
  %w(4.0 5.0).each do |redis_version|
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.14.0
4
+
5
+ * Support Rails 7.1.0.
6
+
3
7
  ## 0.13.1
4
8
  * Fixed last place that tried to log a monotonic clock timestamp
5
9
  instead of a Time instance.
data/Gemfile CHANGED
@@ -4,6 +4,3 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  gem "hiredis-client"
7
-
8
- # Use patched appraisal gem until it is fixed upstream.
9
- gem "appraisal", git: "https://github.com/thoughtbot/appraisal.git", ref: "0c855ae0da89fec74b4d1a01801c55b0e72496d4"
data/docker-compose.yml CHANGED
@@ -3,7 +3,7 @@ version: '2'
3
3
  services:
4
4
  mysql:
5
5
  container_name: mysql
6
- image: mysql:5.7
6
+ image: mysql:8
7
7
  ports:
8
8
  - "3601:3306"
9
9
  environment:
@@ -9,6 +9,18 @@ module ActiveRecord
9
9
  class LogSubscriber
10
10
  IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"] unless defined?(IGNORE_PAYLOAD_NAMES)
11
11
 
12
+ if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("7.1.0")
13
+ def self.reset_runtime
14
+ ActiveRecord::RuntimeRegistry.reset
15
+ end
16
+ def self.runtime
17
+ ActiveRecord::RuntimeRegistry.sql_runtime
18
+ end
19
+ def self.runtime=(value)
20
+ ActiveRecord::RuntimeRegistry.sql_runtime = value
21
+ end
22
+ end
23
+
12
24
  def self.call_count=(value)
13
25
  Thread.current.thread_variable_set(:active_record_sql_call_count, value)
14
26
  end
@@ -56,23 +68,64 @@ module ActiveRecord
56
68
 
57
69
  private
58
70
  def log_sql_statement(payload, event)
59
- name = "#{payload[:name]} (#{event.duration.round(1)}ms)"
71
+ name = if payload[:async]
72
+ "ASYNC #{payload[:name]} (#{payload[:lock_wait].round(1)}ms) (db time #{event.duration.round(1)}ms)"
73
+ else
74
+ "#{payload[:name]} (#{event.duration.round(1)}ms)"
75
+ end
60
76
  name = "CACHE #{name}" if payload[:cached]
61
77
  sql = payload[:sql]
62
- binds = nil
63
-
64
- unless (payload[:binds] || []).empty?
65
- casted_params = type_casted_binds(payload[:type_casted_binds])
66
- binds = " " + payload[:binds].zip(casted_params).map { |attr, value|
67
- render_bind(attr, value)
68
- }.inspect
69
- end
78
+ binds = render_binds(payload)
70
79
 
71
80
  name = colorize_payload_name(name, payload[:name])
72
- sql = color(sql, sql_color(sql), true)
81
+ sql = colorize_sql(sql) if colorize_logging
73
82
 
74
83
  debug " #{name} #{sql}#{binds}"
75
84
  end
85
+
86
+ if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("7.1.0")
87
+ def render_binds(payload)
88
+ binds = nil
89
+ if payload[:binds]&.any?
90
+ casted_params = type_casted_binds(payload[:type_casted_binds])
91
+
92
+ binds = []
93
+ payload[:binds].each_with_index do |attr, i|
94
+ attribute_name = if attr.respond_to?(:name)
95
+ attr.name
96
+ elsif attr.respond_to?(:[]) && attr[i].respond_to?(:name)
97
+ attr[i].name
98
+ else
99
+ nil
100
+ end
101
+
102
+ filtered_params = filter(attribute_name, casted_params[i])
103
+
104
+ binds << render_bind(attr, filtered_params)
105
+ end
106
+ binds = binds.inspect
107
+ binds.prepend(" ")
108
+ end
109
+ return binds
110
+ end
111
+ def colorize_sql(sql)
112
+ color(sql, sql_color(sql), bold: true)
113
+ end
114
+ else
115
+ def render_binds(payload)
116
+ binds = nil
117
+ unless (payload[:binds] || []).empty?
118
+ casted_params = type_casted_binds(payload[:type_casted_binds])
119
+ binds = " " + payload[:binds].zip(casted_params).map { |attr, value|
120
+ render_bind(attr, value)
121
+ }.inspect
122
+ end
123
+ return binds
124
+ end
125
+ def colorize_sql(sql)
126
+ color(sql, sql_color(sql), true)
127
+ end
128
+ end
76
129
  end
77
130
 
78
131
  require "active_record/railties/controller_runtime"
@@ -1,3 +1,3 @@
1
1
  module TimeBandits
2
- VERSION = "0.13.1"
2
+ VERSION = "0.14.0"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -23,6 +23,7 @@ ActiveSupport::LogSubscriber.logger =::Logger.new("/dev/null")
23
23
  # fake Rails
24
24
  module Rails
25
25
  extend self
26
+ ActiveSupport::Cache.format_version = 7.1 if Gem::Version.new(ActiveSupport::VERSION::STRING) >= Gem::Version.new("7.1.0")
26
27
  def cache
27
28
  @cache ||= ActiveSupport::Cache.lookup_store(:mem_cache_store)
28
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_bandits
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-28 00:00:00.000000000 Z
11
+ date: 2023-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thread_variables
@@ -289,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
289
289
  - !ruby/object:Gem::Version
290
290
  version: '0'
291
291
  requirements: []
292
- rubygems_version: 3.4.1
292
+ rubygems_version: 3.4.10
293
293
  signing_key:
294
294
  specification_version: 4
295
295
  summary: Custom performance logging for Rails