<commit_before>import mongoose from 'mongoose';
import shortid from 'shortid';
import bcrypt from 'bcrypt';

const SALT_WORK_FACTOR = 10;

const UserSchema = new mongoose.Schema({
    _id: {type: String, required: true, unique: true, 'default': shortid.generate},
    name: {type: String, required: true},
    password: {type: String, required: true},
    email: {type: String, lowercase: true, required: true},
    email_verified: {type: Boolean, default: false},
});

UserSchema.pre('save', function generatePassword(next) {
    var user = this;
    if (!user.isModified('password')) { return next(); }
    if (user.password.length < 4) {
        return next(new Error('Password must be at least 4 characters long'));
    }

    bcrypt.genSalt(SALT_WORK_FACTOR, (err, salt) => {
        if (err) { return next(err); }

        bcrypt.hash(user.password, salt, (err, hash) => {
            if (err) { return next(err); }

            user.password = <PASSWORD>;
            next();
        });
    });
});

UserSchema.methods.authenticate = function authenticateUser(candidate, next) {
    bcrypt.compare(candidate, this.password, (err, ok) => {
        next(err, ok);
    });
};

const SiteSchema = new mongoose.Schema({
    identifier: {
        type: String,
        required: true,
        unique: true,
        validate: {
            validator: (v) => {
                return /[a-z0-9-]{5,}/.test(v);
            },
            message: 'At least five characters: lowercased letters, numbers and hyphens allowed.',
        },
    }, // part of URL
    name: {type: String, required: true, unique: true},
    admins: [{type: String, ref: 'User', index: true }],
});

const User = mongoose.model('User', UserSchema);
const Site = mongoose.model('Site', SiteSchema);

export {User, Site};<commit_msg>Add index on identifier column<commit_after>import mongoose from 'mongoose';
import shortid from 'shortid';
import bcrypt from 'bcrypt';

const SALT_WORK_FACTOR = 10;

const UserSchema = new mongoose.Schema({
    _id: {type: String, required: true, unique: true, 'default': shortid.generate},
    name: {type: String, required: true},
    password: {type: String, required: true},
    email: {type: String, lowercase: true, required: true},
    email_verified: {type: Boolean, default: false},
});

UserSchema.pre('save', function generatePassword(next) {
    var user = this;
    if (!user.isModified('password')) { return next(); }
    if (user.password.length < 4) {
        return next(new Error('Password must be at least 4 characters long'));
    }

    bcrypt.genSalt(SALT_WORK_FACTOR, (err, salt) => {
        if (err) { return next(err); }

        bcrypt.hash(user.password, salt, (err, hash) => {
            if (err) { return next(err); }

            user.password = <PASSWORD>;
            next();
        });
    });
});

UserSchema.methods.authenticate = function authenticateUser(candidate, next) {
    bcrypt.compare(candidate, this.password, (err, ok) => {
        next(err, ok);
    });
};

const SiteSchema = new mongoose.Schema({
    identifier: {
        type: String,
        required: true,
        unique: true,
        index: true,
        validate: {
            validator: (v) => {
                return /[a-z0-9-]{5,}/.test(v);
            },
            message: 'At least five characters: lowercased letters, numbers and hyphens allowed.',
        },
    }, // part of URL
    name: {type: String, required: true, unique: true},
    admins: [{type: String, ref: 'User', index: true }],
});

const User = mongoose.model('User', UserSchema);
const Site = mongoose.model('Site', SiteSchema);

export {User, Site};
{'fraction_non_alphanumeric': 0.15076754385964913, 'fraction_numerical': 0.003837719298245614, 'mean_word_length': 2.837013669821241, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '3588514', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1114, 'n_words': 317}