不要怂,就是干,撸起袖子干!

Commit 5b09f61a by Sascha Depold

refactored example to push queries without batching or other logic

1 parent 3db4ecb2
Showing with 15 additions and 17 deletions
......@@ -11,22 +11,11 @@ Person.sync({force: true}).on('success', function() {
, count = 10000
, done = 0
var createPeople = function(callback) {
Person.create({name: 'someone'}).on('success', callback).on('failure', function(err) { console.log(err) })
}
var createPeopleBatch = function(batchSize, callback) {
var done = 0
for(var i = 0; i < batchSize; i++)
createPeople(function() { (++done == batchSize) && callback() })
}
var batchCallback = function() {
sys.print(".");
if((done += 50) != count)
createPeopleBatch(50, batchCallback)
else {
console.log("\nFinished creation of " + count + " people. Took: " + (Date.now() - start) + "ms")
var createPerson = function() {
Person.create({name: 'someone'}).on('success', function() {
if(++done == count) {
var duration = (Date.now() - start)
console.log("\nFinished creation of " + count + " people. Took: " + duration + "ms (avg: " + (duration/count) + "ms)")
start = Date.now()
console.log("Will now read them from the database:")
......@@ -34,11 +23,19 @@ Person.sync({force: true}).on('success', function() {
Person.findAll().on('success', function(people) {
console.log("Reading " + people.length + " items took: " + (Date.now() - start) + "ms")
})
} else {
(done % 100 == 0) && sys.print('.')
}
}).on('failure', function(err) {
console.log(err)
})
}
console.log('Creating people :)')
createPeopleBatch(50, batchCallback)
for(var i = 0; i < count; i++) {
createPerson()
}
}).on('failure', function(err) {
console.log(err)
})
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!