Przeglądaj źródła

performance measurements on 250k

Ivan Asmer 6 lat temu
rodzic
commit
344594dc30
2 zmienionych plików z 16 dodań i 7 usunięć
  1. 5 3
      index.js
  2. 11 4
      mm.js

+ 5 - 3
index.js

@@ -82,9 +82,9 @@ const delay       = ms => new Promise(r => setTimeout(r.bind(ms), ms))
             //if (persons.includes(person)){
                 //console.log('WAS HERE',person._id, person.name, person.surname, person.createdAt)
             //}
-            ////for (let friend of person.friends){
-                ////await friend
-            ////}
+            //for (let friend of person.friends){
+                //await friend
+            //}
             //persons.push(person)
 
             now = (new Date()).getTime()
@@ -100,6 +100,8 @@ const delay       = ms => new Promise(r => setTimeout(r.bind(ms), ms))
         return now - start
     }
 
+    //await walker()
+
 
     console.log(await Promise.all([walker(), walker()]))
     console.log(await Promise.all([walker(), walker()]))

+ 11 - 4
mm.js

@@ -53,10 +53,12 @@ module.exports = db => {
             Object.assign(this, obj)
 
 
+
             convertSavables(this)
 
             this.saveRelations()
 
+            this._id = obj._id
         }
 
         get _empty(){
@@ -66,19 +68,24 @@ module.exports = db => {
         set _empty(value){
             if (value){
                 this.then = (cb, err) => {
-                    if (!this._empty){
-                        cb(this)
-                        return this
-                    }
+                    let stamp = (new Date()).getTime()
+                    //if (!this._empty){ //it can't (?) works
+                        //cb(this)
+                        //return this
+                    //}
                     delete this.then
                     if (!this._id)    err(new ReferenceError('Id is empty'))
                     if (!this._class) err(new ReferenceError('Class is empty'))
 
+                    //console.log(this._id)
+
                     this.collection.findOne(this._id).then( data => {
                         if (!data){
                             err(new ReferenceError('Document Not Found'))
                         }
+                        //console.log('FIND', (new Date()).getTime() - stamp)
                         this.populate(data)
+                        //console.log('FIND AND POPULATE', (new Date()).getTime() - stamp)
                         cb(this)
                     })
                     return this