Commit 352a17b0 authored by Kamil Trzciński's avatar Kamil Trzciński

Use Singleton module

This ensures that always only a single instance
of a given class can be created.
parent 86abe907
......@@ -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])
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment