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 ...@@ -7,7 +7,7 @@ class IndexStatus < ApplicationRecord
sha_attribute :last_wiki_commit 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) } scope :for_project, ->(project_id) { where(project_id: project_id) }
end end
---
title: Fix bug with IndexStatus not being set on indexing project
merge_request: 36266
author:
type: fixed
...@@ -163,12 +163,7 @@ module Gitlab ...@@ -163,12 +163,7 @@ module Gitlab
# An index_status should always be created, # An index_status should always be created,
# even if the repository is empty, so we know it's been looked at. # even if the repository is empty, so we know it's been looked at.
@index_status ||= @index_status ||= IndexStatus.safe_find_or_create_by!(project_id: project.id)
begin
IndexStatus.find_or_create_by(project_id: project.id)
rescue ActiveRecord::RecordNotUnique
retry
end
attributes = attributes =
if index_wiki? if index_wiki?
...@@ -177,7 +172,8 @@ module Gitlab ...@@ -177,7 +172,8 @@ module Gitlab
{ last_commit: to_sha, indexed_at: Time.now } { last_commit: to_sha, indexed_at: Time.now }
end end
@index_status.update(attributes) @index_status.update!(attributes)
project.reload_index_status project.reload_index_status
end end
# rubocop: enable CodeReuse/ActiveRecord # 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