Commit 02f27285 authored by James Fargher's avatar James Fargher

Merge branch 'update-bang-elastic-commit-indexer' into 'master'

Fix IndexStatus find_or_create race condition

See merge request gitlab-org/gitlab!36266
parents a60e23f5 afb37c9e
......@@ -7,7 +7,7 @@ class IndexStatus < ApplicationRecord
sha_attribute :last_wiki_commit
validates :project_id, uniqueness: true, presence: true
validates :project_id, presence: true
scope :for_project, ->(project_id) { where(project_id: project_id) }
end
---
title: Fix bug with IndexStatus not being set on indexing project
merge_request: 36266
author:
type: fixed
......@@ -163,12 +163,7 @@ module Gitlab
# An index_status should always be created,
# even if the repository is empty, so we know it's been looked at.
@index_status ||=
begin
IndexStatus.find_or_create_by(project_id: project.id)
rescue ActiveRecord::RecordNotUnique
retry
end
@index_status ||= IndexStatus.safe_find_or_create_by!(project_id: project.id)
attributes =
if index_wiki?
......@@ -177,7 +172,8 @@ module Gitlab
{ last_commit: to_sha, indexed_at: Time.now }
end
@index_status.update(attributes)
@index_status.update!(attributes)
project.reload_index_status
end
# rubocop: enable CodeReuse/ActiveRecord
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment