Resolve "Resolve cross DB issue in CacheMarkdownField (vulnerability_user_mentions)"
What does this MR do and why?
Solve cross-database transaction issue
occurring when calling Note.save! by storing
its VulnerabilityUserMention user mentions after the save commit.
The notes and vulnerability_user_mentions tables belong to two different gitlab schemas
(and possibly two different databases), and they can't be updated in the same transaction.
- Add
store_mentions_after_commit?to theCacheMarkdownFieldconcern. By default it returnsfalse. - When
store_mentions_after_commit?is true, callstore_mentions!after committing, and not directly in theafter_savecallback. - Override
store_mentions_after_commit?inEE::Note, and return true when user mentions areVulnerabilityUserMentions. In that particular case user mentions must be updated after committing the transaction opened byNote.save!.
References
Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
- This solution has been suggested by @engwan in #507439 (comment 2240137886).
- The problem has been discussed at length in #482743 (comment 2239891807).
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
bundle exec rspec --fail-fast \
./spec/models/concerns/cache_markdown_field_spec.rb \
./ee/spec/controllers/projects/security/vulnerabilities/notes_controller_spec.rb && \
FOSS_ONLY=1 bundle exec rspec --fail-fast \
spec/controllers/projects/notes_controller_spec.rb:76
Related to #507439 (closed)
Edited by Fabien Catteau