From eb53275a85aa91b5ce3c6425741439454c1805b0 Mon Sep 17 00:00:00 2001 From: Tomas Hykel Date: Tue, 12 May 2026 23:11:42 +0200 Subject: [PATCH] fix: Reduce amount of locking in ConvertProjectToSemanticIdsJob --- .../convert_project_to_semantic_service.rb | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/app/services/project_identifiers/convert_project_to_semantic_service.rb b/app/services/project_identifiers/convert_project_to_semantic_service.rb index 226c2fe9515..e0f41697f92 100644 --- a/app/services/project_identifiers/convert_project_to_semantic_service.rb +++ b/app/services/project_identifiers/convert_project_to_semantic_service.rb @@ -41,12 +41,10 @@ module ProjectIdentifiers end def call - ApplicationRecord.transaction do - fix_identifier_if_needed - reset_stale_identifiers - backfill_missing_ids - seed_alias_table - end + fix_identifier_if_needed + ApplicationRecord.transaction { reset_stale_identifiers } + ApplicationRecord.transaction { backfill_missing_ids } + ApplicationRecord.transaction { seed_alias_table } end private @@ -57,15 +55,8 @@ module ProjectIdentifiers # Pure format check — no DB queries. return if ProjectIdentifiers::IdentifierAutofix::ProblematicIdentifiers.valid_format?(project.identifier) - # Serialize all concurrent identifier assignments with a transaction-level - # advisory lock. The lock is automatically released when the outer - # ApplicationRecord.transaction commits, so the next job waiting on it - # always reads a fully up-to-date exclusion set and can never generate a - # duplicate. Without this, parallel jobs can read the same exclusion set - # before any of them commits, then all pick the same candidate. - OpenProject::Mutex.with_advisory_lock( - Project, "semantic_identifier_generation", transaction: true - ) do + # Identifier assignments must run one at a time to avoid conflicts with concurrent renames or conversions. + OpenProject::Mutex.with_advisory_lock(Project, "semantic_identifier_generation") do assign_semantic_identifier end end