Class: Gitlab::Database::PostgresTableSize

Inherits:
SharedModel
  • Object
show all
Defined in:
lib/gitlab/database/postgres_table_size.rb

Constant Summary collapse

SMALL =
10.gigabytes
MEDIUM =
50.gigabytes
LARGE =
100.gigabytes
ALERT =
25.gigabytes
CLASSIFICATION =
{
  small: 0...SMALL,
  medium: SMALL...MEDIUM,
  large: MEDIUM...LARGE,
  over_limit: LARGE...
}.freeze

Constants inherited from SharedModel

SharedModel::SHARED_SCHEMAS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SharedModel

connection, #connection_db_config, connection_pool, ensure_connection_set!, using_connection

Class Method Details

.by_table_name(table_name) ⇒ Object



27
28
29
# File 'lib/gitlab/database/postgres_table_size.rb', line 27

def self.by_table_name(table_name)
  where(table_name: table_name).first
end

Instance Method Details

#alert_report_hashObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/gitlab/database/postgres_table_size.rb', line 48

def alert_report_hash
  {
    identifier: identifier,
    schema_name: schema_name,
    table_name: table_name,
    total_size: total_size,
    table_size: table_size,
    index_size: index_size,
    toast_size: toast_size,
    size_in_bytes: size_in_bytes,
    classification: size_classification,
    feature_categories: feature_categories
  }
end

#feature_categoriesObject



44
45
46
# File 'lib/gitlab/database/postgres_table_size.rb', line 44

def feature_categories
  database_entries.find_by_table_name(table_name)&.feature_categories
end

#size_classificationObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gitlab/database/postgres_table_size.rb', line 31

def size_classification
  case size_in_bytes
  when CLASSIFICATION[:small]
    'small'
  when CLASSIFICATION[:medium]
    'medium'
  when CLASSIFICATION[:large]
    'large'
  when CLASSIFICATION[:over_limit]
    'over_limit'
  end
end