Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
352a17b0
Commit
352a17b0
authored
Nov 09, 2021
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Singleton module
This ensures that always only a single instance of a given class can be created.
parent
86abe907
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
5 deletions
+3
-5
lib/gitlab/database/query_analyzer.rb
lib/gitlab/database/query_analyzer.rb
+2
-4
spec/lib/gitlab/database/query_analyzer_spec.rb
spec/lib/gitlab/database/query_analyzer_spec.rb
+1
-1
No files found.
lib/gitlab/database/query_analyzer.rb
View file @
352a17b0
...
...
@@ -5,16 +5,14 @@ module Gitlab
# The purpose of this class is to implement a various query analyzers based on `pg_query`
# And process them all via `Gitlab::Database::QueryAnalyzers::*`
class
QueryAnalyzer
include
::
Singleton
ANALYZERS
=
[].
freeze
Parsed
=
Struct
.
new
(
:sql
,
:connection
,
:pg
)
def
self
.
instance
@instance
||=
new
end
def
hook!
@subscriber
=
ActiveSupport
::
Notifications
.
subscribe
(
'sql.active_record'
)
do
|
event
|
process_sql
(
event
.
payload
[
:sql
],
event
.
payload
[
:connection
])
...
...
spec/lib/gitlab/database/query_analyzer_spec.rb
View file @
352a17b0
...
...
@@ -65,7 +65,7 @@ RSpec.describe Gitlab::Database::QueryAnalyzer do
def
process_sql
(
sql
)
ApplicationRecord
.
load_balancer
.
read_write
do
|
connection
|
described_class
.
new
.
send
(
:process_sql
,
sql
,
connection
)
described_class
.
instance
.
send
(
:process_sql
,
sql
,
connection
)
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment