diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-17 00:29:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-17 00:29:57 +0300 |
commit | 899da2d359848b005984373052b2e697fd5d10f2 (patch) | |
tree | b4b93613f08ed28f8c954b2517742e8d71029ed7 /app/models | |
parent | 6d558d71eba0e5c8025e2a093ce8d144b1fdd4cf (diff) |
Add latest changes from gitlab-org/gitlab@16-6-stable-ee
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/pages_deployment.rb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/app/models/pages_deployment.rb b/app/models/pages_deployment.rb index 2aa36a94171..0d87a8f6cf6 100644 --- a/app/models/pages_deployment.rb +++ b/app/models/pages_deployment.rb @@ -5,6 +5,9 @@ class PagesDeployment < ApplicationRecord include EachBatch include FileStoreMounter include Gitlab::Utils::StrongMemoize + include SafelyChangeColumnDefault + + columns_changing_default :upload_ready attribute :file_store, :integer, default: -> { ::Pages::DeploymentUploader.default_store } @@ -18,7 +21,12 @@ class PagesDeployment < ApplicationRecord scope :with_files_stored_remotely, -> { where(file_store: ::ObjectStorage::Store::REMOTE) } scope :project_id_in, ->(ids) { where(project_id: ids) } scope :with_path_prefix, ->(prefix) { where("COALESCE(path_prefix, '') = ?", prefix.to_s) } - scope :active, -> { where(deleted_at: nil).order(created_at: :desc) } + + # We have to mark the PagesDeployment upload as ready to ensure we only + # serve PagesDeployment which files are already uploaded. + scope :upload_ready, -> { where(upload_ready: true) } + + scope :active, -> { upload_ready.where(deleted_at: nil).order(created_at: :desc) } scope :deactivated, -> { where('deleted_at < ?', Time.now.utc) } validates :file, presence: true @@ -64,6 +72,18 @@ class PagesDeployment < ApplicationRecord return unless previous_changes.key?(:file) store_file_now! + mark_upload_as_finished! + end + + # We have to mark the PagesDeployment upload as ready to ensure we only + # serve PagesDeployment which files are already uploaded. + # + # This is required because we're uploading the file outside of the db transaction + # (https://gitlab.com/gitlab-org/gitlab/-/merge_requests/114774) + def mark_upload_as_finished! + return unless file && file.exists? + + update_column(:upload_ready, true) end end |