summaryrefslogtreecommitdiff
path: root/lib/gitlab/database/postgresql_adapter/empty_query_ping.rb
blob: 906312478ac5a8e3854fc144c4ede020bb015f38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

# rubocop:disable Gitlab/ModuleWithInstanceVariables
module Gitlab
  module Database
    module PostgresqlAdapter
      module EmptyQueryPing
        # ActiveRecord uses `SELECT 1` to check if the connection is alive
        # We patch this here to use an empty query instead, which is a bit faster
        def active?
          @lock.synchronize do
            @connection.query ';'
          end
          true
        rescue PG::Error
          false
        end
      end
    end
  end
end
# rubocop:enable Gitlab/ModuleWithInstanceVariables