<commit_before>var people = (function () {

var exports = {};

var people_dict;
var people_by_name_dict;
var people_by_user_id_dict;
var realm_people_dict;
var cross_realm_dict;
var pm_recipient_count_dict;
var my_user_id;

// We have an init() function so that our automated tests
// can easily clear data.
exports.init = function () {
    // The following three Dicts point to the same objects
    // (all people we've seen), but people_dict can have duplicate
    // keys related to email changes.  We want to deprecate
    // people_dict over time and always do lookups by user_id.
    people_dict = new Dict({fold_case: true});
    people_by_name_dict = new Dict({fold_case: true});
    people_by_user_id_dict = new Dict();

    realm_people_dict = new Dict();
    cross_realm_dict = new Dict(); // keyed by user_id
    pm_recipient_count_dict = new Dict();
};

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

exports.get_person_from_user_id = function (user_id) {
    if (!people_by_user_id_dict.has(user_id)) {
        blueslip.error('Unknown user_id in get_person_from_user_id: ' + user_id);
        return undefined;
    }
    return people_by_user_id_dict.get(user_id);
};

exports.get_by_email = function (email) {
    var person = people_dict.get(email);

    if (!person) {
        return undefined;
    }

    if (person.email.toLowerCase() !== email.toLowerCase()) {
        blueslip.warn(
            'Obsolete email passed to get_by_email: ' + email +
            ' new email = ' + person.email
        );
    }

    return person;
};

exports.id_matches_email_operand = function (user_id, email) {
    var person = exports.get_by_email(email);

    if (!person) {
        // The user may type bad data into the search bar, so
        // we don't complain too loud here.
        blueslip.debug('User email operand unknown: ' + email);
        return false;
    }

    return (person.user_id === user_id);
};

exports.update_email = function (user_id, new_email) {
    var person = people_by_user_id_dict.get(user_id);
    person.email = new_email;
    people_dict.set(new_email, person);

    // For legacy reasons we don't delete the old email
    // keys in our dictionaries, so that reverse lookups
    // still work correctly.
};

exports.get_user_id = function (email) {
    var person = people.get_by_email(email);
    if (person === undefined) {
        // Our blueslip reporting here is a bit complicated, but
        // there are known race conditions after reload, and we
        // expect occasional failed lookups, but they should resolve
        // after five seconds.
        var error_msg = 'Unknown email for get_user_id: ' + email;
        blueslip.debug(error_msg);
        setTimeout(function () {
            if (!people_dict.has(email)) {
                blueslip.error(error_msg);
            }
        }, 5000);
        return undefined;
    }
    var user_id = person.user_id;
    if (!user_id) {
        blueslip.error('No userid found for ' + email);
        return undefined;
    }

    return user_id;<commit_msg>Make get_user_id blueslip errors clear again.<commit_after>var people = (function () {

var exports = {};

var people_dict;
var people_by_name_dict;
var people_by_user_id_dict;
var realm_people_dict;
var cross_realm_dict;
var pm_recipient_count_dict;
var my_user_id;

// We have an init() function so that our automated tests
// can easily clear data.
exports.init = function () {
    // The following three Dicts point to the same objects
    // (all people we've seen), but people_dict can have duplicate
    // keys related to email changes.  We want to deprecate
    // people_dict over time and always do lookups by user_id.
    people_dict = new Dict({fold_case: true});
    people_by_name_dict = new Dict({fold_case: true});
    people_by_user_id_dict = new Dict();

    realm_people_dict = new Dict();
    cross_realm_dict = new Dict(); // keyed by user_id
    pm_recipient_count_dict = new Dict();
};

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

exports.get_person_from_user_id = function (user_id) {
    if (!people_by_user_id_dict.has(user_id)) {
        blueslip.error('Unknown user_id in get_person_from_user_id: ' + user_id);
        return undefined;
    }
    return people_by_user_id_dict.get(user_id);
};

exports.get_by_email = function (email) {
    var person = people_dict.get(email);

    if (!person) {
        return undefined;
    }

    if (person.email.toLowerCase() !== email.toLowerCase()) {
        blueslip.warn(
            'Obsolete email passed to get_by_email: ' + email +
            ' new email = ' + person.email
        );
    }

    return person;
};

exports.id_matches_email_operand = function (user_id, email) {
    var person = exports.get_by_email(email);

    if (!person) {
        // The user may type bad data into the search bar, so
        // we don't complain too loud here.
        blueslip.debug('User email operand unknown: ' + email);
        return false;
    }

    return (person.user_id === user_id);
};

exports.update_email = function (user_id, new_email) {
    var person = people_by_user_id_dict.get(user_id);
    person.email = new_email;
    people_dict.set(new_email, person);

    // For legacy reasons we don't delete the old email
    // keys in our dictionaries, so that reverse lookups
    // still work correctly.
};

exports.get_user_id = function (email) {
    var person = people.get_by_email(email);
    if (person === undefined) {
        var error_msg = 'Unknown email for get_user_id: ' + email;
        blueslip.error(error_msg);
        return undefined;
    }
    var user_id = person.user_id;
    if (!user_id) {
        blueslip.error('No userid found for ' + email);
        return undefined;
    }

    return user_id;
{'fraction_non_alphanumeric': 0.10148686030428769, 'fraction_numerical': 0.0006915629322268327, 'mean_word_length': 2.869565217391304, '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': '2929146', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1817, 'n_words': 516}