diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-12 15:10:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-12 15:10:24 +0300 |
commit | 71a67d17b02e7b8dec2f4c257f6734dc7818fb1e (patch) | |
tree | 6b45633257869a67fd534bd2cf899b93a48794c0 /app/models/container_repository.rb | |
parent | 133ec9237af290062aae70e6f115db69b51c88de (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/container_repository.rb')
-rw-r--r-- | app/models/container_repository.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb index 6c8cfa6b88a..6e0d0e347c9 100644 --- a/app/models/container_repository.rb +++ b/app/models/container_repository.rb @@ -7,6 +7,7 @@ class ContainerRepository < ApplicationRecord include Sortable WAITING_CLEANUP_STATUSES = %i[cleanup_scheduled cleanup_unfinished].freeze + REQUIRING_CLEANUP_STATUSES = %i[cleanup_unscheduled cleanup_scheduled].freeze belongs_to :project @@ -31,6 +32,7 @@ class ContainerRepository < ApplicationRecord scope :for_project_id, ->(project_id) { where(project_id: project_id) } scope :search_by_name, ->(query) { fuzzy_search(query, [:name], use_minimum_char_limit: false) } scope :waiting_for_cleanup, -> { where(expiration_policy_cleanup_status: WAITING_CLEANUP_STATUSES) } + scope :expiration_policy_started_at_nil_or_before, ->(timestamp) { where('expiration_policy_started_at < ? OR expiration_policy_started_at IS NULL', timestamp) } def self.exists_by_path?(path) where( @@ -39,6 +41,23 @@ class ContainerRepository < ApplicationRecord ).exists? end + def self.with_enabled_policy + joins("INNER JOIN container_expiration_policies ON container_repositories.project_id = container_expiration_policies.project_id") + .where(container_expiration_policies: { enabled: true }) + end + + def self.requiring_cleanup + where( + container_repositories: { expiration_policy_cleanup_status: REQUIRING_CLEANUP_STATUSES }, + project_id: ::ContainerExpirationPolicy.runnable_schedules + .select(:project_id) + ) + end + + def self.with_unfinished_cleanup + with_enabled_policy.cleanup_unfinished + end + # rubocop: disable CodeReuse/ServiceClass def registry @registry ||= begin |