mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
Merge pull request #23183 from opf/fix/attempt-fixing-bg-job-admin-page
perf: Reduce amount of advisory locking in ConvertProjectToSemanticService
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user