Last active
August 29, 2015 14:25
-
-
Save barisusakli/1c89f0534038f43d800b to your computer and use it in GitHub Desktop.
Create lots of users in nodebb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
/*globals require, console, process */ | |
var nconf = require('nconf'); | |
var async = require('async'); | |
nconf.file({ | |
file: 'config.json' | |
}); | |
var db = require('./src/database'); | |
db.init(function(err) { | |
if (err) { | |
console.log('NodeBB could not connect to your redis database. Redis returned the following error: ' + err.message); | |
process.exit(); | |
} | |
createUsers(function(err) { | |
if (err) { | |
console.log(err.message); | |
process.exit(); | |
} | |
console.log('users created'); | |
process.exit(); | |
}); | |
}); | |
function createUsers(callback) { | |
var user = require('./src/user'); | |
var count = 100000; | |
var users = []; | |
for (var i=0; i<count; ++i) { | |
var username = makeid(); | |
users.push({username: username, email: username + '@nodebb.org'}); | |
} | |
var index = 0; | |
async.eachSeries(users, function(userData, next) { | |
user.create({username: userData.username, email: userData.email}, function(err) { | |
if (err) { | |
return next(err); | |
} | |
console.log('created ' + userData.username + ' - ' + index + ' / ' + count); | |
++index; | |
next(); | |
}); | |
}, callback); | |
} | |
function makeid() | |
{ | |
var text = ''; | |
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
for( var i=0; i < 8; i++ ) | |
text += possible.charAt(Math.floor(Math.random() * possible.length)); | |
return text; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment