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 the CacheMarkdownField concern. By default it returns false.
  • When store_mentions_after_commit? is true, call store_mentions! after committing, and not directly in the after_save callback.
  • Override store_mentions_after_commit? in EE::Note, and return true when user mentions are VulnerabilityUserMentions. In that particular case user mentions must be updated after committing the transaction opened by Note.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.

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

Merge request reports

Loading