diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /lib/gitlab/query_limiting | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'lib/gitlab/query_limiting')
-rw-r--r-- | lib/gitlab/query_limiting/active_support_subscriber.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/query_limiting/transaction.rb | 22 |
2 files changed, 20 insertions, 4 deletions
diff --git a/lib/gitlab/query_limiting/active_support_subscriber.rb b/lib/gitlab/query_limiting/active_support_subscriber.rb index 4bfd526914b..49f76ce7814 100644 --- a/lib/gitlab/query_limiting/active_support_subscriber.rb +++ b/lib/gitlab/query_limiting/active_support_subscriber.rb @@ -8,7 +8,7 @@ module Gitlab def sql(event) return if !::Gitlab::QueryLimiting::Transaction.current || event.payload.fetch(:cached, event.payload[:name] == 'CACHE') - ::Gitlab::QueryLimiting::Transaction.current.increment + ::Gitlab::QueryLimiting::Transaction.current.increment(event.payload[:sql]) ::Gitlab::QueryLimiting::Transaction.current.executed_sql(event.payload[:sql]) end end diff --git a/lib/gitlab/query_limiting/transaction.rb b/lib/gitlab/query_limiting/transaction.rb index 643b2540c37..2e31849caaa 100644 --- a/lib/gitlab/query_limiting/transaction.rb +++ b/lib/gitlab/query_limiting/transaction.rb @@ -57,12 +57,28 @@ module Gitlab raise(error) if raise_error? end - def increment - @count += 1 if enabled? + def increment(sql = nil) + @count += 1 if enabled? && !ignorable?(sql) + end + + GEO_NODES_LOAD = 'SELECT 1 AS one FROM "geo_nodes" LIMIT 1' + LICENSES_LOAD = 'SELECT "licenses".* FROM "licenses" ORDER BY "licenses"."id"' + ATTR_INTROSPECTION = %r/SELECT .*\ba.attname\b.* (FROM|JOIN) pg_attribute a/m.freeze + + # queries can be safely ignored if they are amoritized in regular usage + # (i.e. only requested occasionally and otherwise cached). + def ignorable?(sql) + return true if sql&.include?(GEO_NODES_LOAD) + return true if sql&.include?(LICENSES_LOAD) + return true if ATTR_INTROSPECTION =~ sql + + false end def executed_sql(sql) - @sql_executed << sql if @count <= LOG_THRESHOLD + return if @count > LOG_THRESHOLD || ignorable?(sql) + + @sql_executed << sql end def raise_error? |