diff options
Diffstat (limited to 'lib/gitlab/database/reindexing/reindex_action.rb')
-rw-r--r-- | lib/gitlab/database/reindexing/reindex_action.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/gitlab/database/reindexing/reindex_action.rb b/lib/gitlab/database/reindexing/reindex_action.rb index 0928ef90e5d..8c59cffe5fb 100644 --- a/lib/gitlab/database/reindexing/reindex_action.rb +++ b/lib/gitlab/database/reindexing/reindex_action.rb @@ -6,13 +6,20 @@ module Gitlab class ReindexAction < ActiveRecord::Base self.table_name = 'postgres_reindex_actions' + belongs_to :index, foreign_key: :index_identifier, class_name: 'Gitlab::Database::PostgresIndex' enum state: { started: 0, finished: 1, failed: 2 } + # Amount of time to consider a previous reindexing *recent* + RECENT_THRESHOLD = 7.days + + scope :recent, -> { where(state: :finished).where('action_end > ?', Time.zone.now - RECENT_THRESHOLD) } + def self.keep_track_of(index, &block) action = create!( index_identifier: index.identifier, action_start: Time.zone.now, - ondisk_size_bytes_start: index.ondisk_size_bytes + ondisk_size_bytes_start: index.ondisk_size_bytes, + bloat_estimate_bytes_start: index.bloat_size ) yield |