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

Commit 5b09f61a by Sascha Depold

refactored example to push queries without batching or other logic

1 parent 3db4ecb2
Showing with 23 additions and 25 deletions
...@@ -11,34 +11,31 @@ Person.sync({force: true}).on('success', function() { ...@@ -11,34 +11,31 @@ Person.sync({force: true}).on('success', function() {
, count = 10000 , count = 10000
, done = 0 , done = 0
var createPeople = function(callback) { var createPerson = function() {
Person.create({name: 'someone'}).on('success', callback).on('failure', function(err) { console.log(err) }) Person.create({name: 'someone'}).on('success', function() {
} if(++done == count) {
var createPeopleBatch = function(batchSize, callback) { var duration = (Date.now() - start)
var done = 0 console.log("\nFinished creation of " + count + " people. Took: " + duration + "ms (avg: " + (duration/count) + "ms)")
for(var i = 0; i < batchSize; i++) start = Date.now()
createPeople(function() { (++done == batchSize) && callback() }) console.log("Will now read them from the database:")
}
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")
start = Date.now() Person.findAll().on('success', function(people) {
console.log("Will now read them from the database:") console.log("Reading " + people.length + " items took: " + (Date.now() - start) + "ms")
})
Person.findAll().on('success', function(people) { } else {
console.log("Reading " + people.length + " items took: " + (Date.now() - start) + "ms") (done % 100 == 0) && sys.print('.')
}) }
} }).on('failure', function(err) {
console.log(err)
})
} }
console.log('Creating people :)') console.log('Creating people :)')
createPeopleBatch(50, batchCallback) for(var i = 0; i < count; i++) {
createPerson()
}
}).on('failure', function(err) { }).on('failure', function(err) {
console.log(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!