Class: Gitlab::Database::QueryAnalyzers::Base
- Inherits:
-
Object
- Object
- Gitlab::Database::QueryAnalyzers::Base
show all
- Defined in:
- lib/gitlab/database/query_analyzers/base.rb
Constant Summary
collapse
- QueryAnalyzerError =
Exception to ensure that is not easily rescued when running in test env
Class.new(Exception)
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.suppress_in_rspec=(value) ⇒ Object
Sets the attribute suppress_in_rspec
39
40
41
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 39
def suppress_in_rspec=(value)
@suppress_in_rspec = value
end
|
Class Method Details
.analyze(parsed) ⇒ Object
79
80
81
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 79
def self.analyze(parsed)
raise NotImplementedError
end
|
.analyzer_key ⇒ Object
91
92
93
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 91
def self.analyzer_key
@analyzer_key ||= self.name.demodulize.underscore.to_sym
end
|
.begin! ⇒ Object
63
64
65
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 63
def self.begin!
Thread.current[self.context_key] = {}
end
|
.context ⇒ Object
71
72
73
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 71
def self.context
Thread.current[self.context_key]
end
|
.context_key ⇒ Object
83
84
85
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 83
def self.context_key
@context_key ||= :"analyzer_#{self.analyzer_key}_context"
end
|
.enabled? ⇒ Boolean
75
76
77
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 75
def self.enabled?
raise NotImplementedError
end
|
.end! ⇒ Object
67
68
69
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 67
def self.end!
Thread.current[self.context_key] = nil
end
|
.requires_tracking?(parsed) ⇒ Boolean
20
21
22
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 20
def self.requires_tracking?(parsed)
false
end
|
.skip_cached?(parsed) ⇒ Boolean
Cached queries are not analyzed by default, even if they’d require tracking. Override skip_cached? in your analyzer to analyze cached queries.
16
17
18
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 16
def self.skip_cached?(parsed)
parsed.cached?
end
|
.suppress=(value) ⇒ Object
24
25
26
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 24
def self.suppress=(value)
Thread.current[self.suppress_key] = value
end
|
.suppress_key ⇒ Object
87
88
89
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 87
def self.suppress_key
@suppress_key ||= :"analyzer_#{self.analyzer_key}_suppressed"
end
|
.suppress_schema_issues_for_decomposed_tables ⇒ Object
During database decomposition, db migrations using tables that will be decomposed will begin to contravene their configuration for intended gitlab_schema and database connection. As these migrations already exist, ideally they should be finalized and removed prior to decomposition. In this situations, it’s necessary to suppress warnings related to their incorrect connection and schema to progress our CI pipelines.
47
48
49
50
51
52
53
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 47
def self.suppress_schema_issues_for_decomposed_tables
Gitlab::Database::QueryAnalyzers::RestrictAllowedSchemas.with_suppressed do
Gitlab::Database::QueryAnalyzers::GitlabSchemasValidateConnection.with_suppressed do
yield
end
end
end
|
.suppressed? ⇒ Boolean
10
11
12
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 10
def self.suppressed?
Thread.current[self.suppress_key] || @suppress_in_rspec
end
|
.with_suppressed(value = true, &blk) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/gitlab/database/query_analyzers/base.rb', line 55
def self.with_suppressed(value = true, &blk)
previous = self.suppressed?
self.suppress = value
yield
ensure
self.suppress = previous
end
|