Update garbage collect algorithm. Fixed some tests appearantly :)
This commit is contained in:
		
							parent
							
								
									8e4cf83330
								
							
						
					
					
						commit
						37ac7787d0
					
				@ -71,21 +71,32 @@ module.exports = function (Y /* :any */) {
 | 
				
			|||||||
      this.gcTimeout = opts.gcTimeout || 5000
 | 
					      this.gcTimeout = opts.gcTimeout || 5000
 | 
				
			||||||
      var os = this
 | 
					      var os = this
 | 
				
			||||||
      function garbageCollect () {
 | 
					      function garbageCollect () {
 | 
				
			||||||
        return new Promise((resolve) => {
 | 
					        return os.whenTransactionsFinished().then(function () {
 | 
				
			||||||
          os.requestTransaction(function * () {
 | 
					          if (os.gc1.length > 0 || os.gc2.length > 0) {
 | 
				
			||||||
            if (os.y.connector != null && os.y.connector.isSynced) {
 | 
					            return new Promise((resolve) => {
 | 
				
			||||||
              for (var i = 0; i < os.gc2.length; i++) {
 | 
					              os.requestTransaction(function * () {
 | 
				
			||||||
                var oid = os.gc2[i]
 | 
					                if (os.y.connector != null && os.y.connector.isSynced) {
 | 
				
			||||||
                yield* this.garbageCollectOperation(oid)
 | 
					                  for (var i = 0; i < os.gc2.length; i++) {
 | 
				
			||||||
              }
 | 
					                    var oid = os.gc2[i]
 | 
				
			||||||
              os.gc2 = os.gc1
 | 
					                    yield* this.garbageCollectOperation(oid)
 | 
				
			||||||
              os.gc1 = []
 | 
					                  }
 | 
				
			||||||
            }
 | 
					                  os.gc2 = os.gc1
 | 
				
			||||||
 | 
					                  os.gc1 = []
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                // TODO: Use setInterval here instead (when garbageCollect is called several times there will be several timeouts..)
 | 
				
			||||||
 | 
					                if (os.gcTimeout > 0) {
 | 
				
			||||||
 | 
					                  os.gcInterval = setTimeout(garbageCollect, os.gcTimeout)
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                resolve()
 | 
				
			||||||
 | 
					              })
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					          } else {
 | 
				
			||||||
 | 
					            // TODO: see above
 | 
				
			||||||
            if (os.gcTimeout > 0) {
 | 
					            if (os.gcTimeout > 0) {
 | 
				
			||||||
              os.gcInterval = setTimeout(garbageCollect, os.gcTimeout)
 | 
					              os.gcInterval = setTimeout(garbageCollect, os.gcTimeout)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            resolve()
 | 
					            return Promise.resolve()
 | 
				
			||||||
          })
 | 
					          }
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      this.garbageCollect = garbageCollect
 | 
					      this.garbageCollect = garbageCollect
 | 
				
			||||||
@ -205,8 +216,10 @@ module.exports = function (Y /* :any */) {
 | 
				
			|||||||
    apply (ops) {
 | 
					    apply (ops) {
 | 
				
			||||||
      for (var key in ops) {
 | 
					      for (var key in ops) {
 | 
				
			||||||
        var o = ops[key]
 | 
					        var o = ops[key]
 | 
				
			||||||
        var required = Y.Struct[o.struct].requiredOps(o)
 | 
					        if (o.id == null || o.id[0] !== this.y.connector.userId) {
 | 
				
			||||||
        this.whenOperationsExist(required, o)
 | 
					          var required = Y.Struct[o.struct].requiredOps(o)
 | 
				
			||||||
 | 
					          this.whenOperationsExist(required, o)
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
@ -390,7 +403,7 @@ module.exports = function (Y /* :any */) {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    requestTransaction (makeGen/* :any */, callImmediately) {
 | 
					    requestTransaction (makeGen/* :any */, callImmediately) {
 | 
				
			||||||
      if (true || callImmediately) { // TODO: decide whether this is ok or not..
 | 
					      if (false || callImmediately) { // TODO: decide whether this is ok or not..
 | 
				
			||||||
        this.waitingTransactions.push(makeGen)
 | 
					        this.waitingTransactions.push(makeGen)
 | 
				
			||||||
        if (!this.transactionInProgress) {
 | 
					        if (!this.transactionInProgress) {
 | 
				
			||||||
          this.transactionInProgress = true
 | 
					          this.transactionInProgress = true
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user