Follow-up from "Store mentioned users, groups, projects in DB using postgres array type"

Extract code for saving and storing the mentions to a common method to DRY the code. Investigate the option of moving storing the mentions to the after_save callback. There are some issues with calling store_mentions! from after_save callback in specs where 2 calls happen within same transaction I think and a ActiveRecord::RecordNotUnique exception is thrown.

The following discussion from !19088 (merged) should be addressed:

  • @yorickpeterse started a discussion:

    Seeing how we have this pattern in a bunch of places, I suggest creating a method called save_and_store_mentions(*args). This method passes its arguments to save and calls store_mentions! if save returned true. This method would also wrap these calls in a transaction. This way we can simply use the following here:

    if snippet.save_and_store_mentions
      ...
    end

    Feel free to move this to a follow-up issue, as it's not crucial for now.

Edited Oct 05, 2025 by 🤖 GitLab Bot 🤖
Assignee Loading
Time tracking Loading