arlequin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/arlequin/middleware.rb +40 -0
- data/lib/arlequin.rb +9 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 64dab272387e862b66546a8de88779cc36ffbdfaa0a6082125b8404509fec181
|
4
|
+
data.tar.gz: 0c1d6fe9c4af985484476e81645ce54a1a1391ed19765276dd9d1915bc12b514
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6dab0e3d89077eccf1a50591045e75720bade0b638ff4ab5c2e892c7297b6b12c314cdb25047094b50ac4a45895e18ebb6e2a742409dc290cb7d8620fa911995
|
7
|
+
data.tar.gz: 194ba82a1169e3abec5d4114bd1fae8e3c51b169103f8ae3c2ae8fea8cb4bedc596e0681fbb75840fa6b94f0ea34e1e8acf431eb71e6ddf5efb9097fca91f503
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Arlequin
|
4
|
+
class Middleware
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
# Set up a query counter
|
11
|
+
@queries = Hash.new { |hash, key| hash[key] = 0 }
|
12
|
+
|
13
|
+
ActiveSupport::Notifications.subscribe("sql.active_record", &method(:on_sql))
|
14
|
+
|
15
|
+
status, headers, response = @app.call(env)
|
16
|
+
|
17
|
+
# Detect and log N+1 queries
|
18
|
+
log_n_plus_one_warnings
|
19
|
+
|
20
|
+
[ status, headers, response ]
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def on_sql(_name, _start, _finish, _id, payload)
|
26
|
+
return if payload[:name] == "SCHEMA" # Skip schema queries
|
27
|
+
|
28
|
+
query = payload[:sql]
|
29
|
+
@queries[query] += 1
|
30
|
+
end
|
31
|
+
|
32
|
+
def log_n_plus_one_warnings
|
33
|
+
@queries.each do |query, count|
|
34
|
+
if count > 1
|
35
|
+
Rails.logger.warn("N+1 query detected: #{query}, executed #{count} times")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/arlequin.rb
ADDED
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arlequin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dominic Goulet
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
description: Performance Logger Gem
|
28
|
+
email: dominic.goulet@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/arlequin.rb
|
34
|
+
- lib/arlequin/middleware.rb
|
35
|
+
homepage: https://rubygems.org/gems/arlequin
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.4.19
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Arlequin performance logger gem
|
58
|
+
test_files: []
|