<commit_before>var user_groups = (function () {

var exports = {};

var user_group_name_dict;
var user_group_by_id_dict;

// We have an init() function so that our automated tests
// can easily clear data.
exports.init = function () {
    user_group_name_dict = new Dict({fold_case: true});
    user_group_by_id_dict = new Dict();
};

// WE INITIALIZE DATA STRUCTURES HERE!
exports.init();

exports.add = function (user_group) {
    // Reformat the user group members structure to be a dict.
    user_group.members = Dict.from_array(user_group.members);
    user_group_name_dict.set(user_group.name, user_group);
    user_group_by_id_dict.set(user_group.id, user_group);
};

exports.remove = function (user_group) {
    user_group_name_dict.del(user_group.name);
    user_group_by_id_dict.del(user_group.id);
};

exports.get_user_group_from_id = function (group_id) {
    if (!user_group_by_id_dict.has(group_id)) {
        blueslip.error('Unknown group_id in get_user_group_from_id: ' + group_id);
        return;
    }
    return user_group_by_id_dict.get(group_id);
};

exports.update = function (event) {
    var group = exports.get_user_group_from_id(event.group_id);
    if (event.data.name !== undefined) {
        group.name = event.data.name;
    }
    if (event.data.description !== undefined) {
        group.description = event.data.description;
    }
};

exports.get_user_group_from_name = function (name) {
    return user_group_name_dict.get(name);<commit_msg>user-groups: Update user_group_name_dict, when name/description is edited.<commit_after>var user_groups = (function () {

var exports = {};

var user_group_name_dict;
var user_group_by_id_dict;

// We have an init() function so that our automated tests
// can easily clear data.
exports.init = function () {
    user_group_name_dict = new Dict({fold_case: true});
    user_group_by_id_dict = new Dict();
};

// WE INITIALIZE DATA STRUCTURES HERE!
exports.init();

exports.add = function (user_group) {
    // Reformat the user group members structure to be a dict.
    user_group.members = Dict.from_array(user_group.members);
    user_group_name_dict.set(user_group.name, user_group);
    user_group_by_id_dict.set(user_group.id, user_group);
};

exports.remove = function (user_group) {
    user_group_name_dict.del(user_group.name);
    user_group_by_id_dict.del(user_group.id);
};

exports.get_user_group_from_id = function (group_id) {
    if (!user_group_by_id_dict.has(group_id)) {
        blueslip.error('Unknown group_id in get_user_group_from_id: ' + group_id);
        return;
    }
    return user_group_by_id_dict.get(group_id);
};

exports.update = function (event) {
    var group = exports.get_user_group_from_id(event.group_id);
    if (event.data.name !== undefined) {
        group.name = event.data.name;
        user_group_name_dict.del(group.name);
        user_group_name_dict.set(group.name, group);
    }
    if (event.data.description !== undefined) {
        group.description = event.data.description;
        user_group_name_dict.del(group.name);
        user_group_name_dict.set(group.name, group);
    }
};

exports.get_user_group_from_name = function (name) {
    return user_group_name_dict.get(name);
{'fraction_non_alphanumeric': 0.11436584605796198, 'fraction_numerical': 0.0, 'mean_word_length': 4.031347962382445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6478344', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1102, 'n_words': 203}