feat: faster rest loader

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-08-08 09:43:50 +08:00
parent 6de01c7b9e
commit f8b5c6fb72
2 changed files with 68 additions and 64 deletions

View File

@ -291,17 +291,16 @@ function CheckGlobalTime() {
global.SAVE_CONST();
});
setTimeout(() => {
global.DELTA_CURRENT_TIME = global.DELTA_CURRENT_TIME * -1;
setTimeout(() => {
global.DELTA_CURRENT_TIME = global.DELTA_CURRENT_TIME * -1
if (!global.CAN_START) {
let temp = global.DELTA_CURRENT_TIME
global.DELTA_CURRENT_TIME = 3000;
setTimeout(() => {
let checkTaskId = setInterval(() => {
if (global.CAN_START) {
global.DELTA_CURRENT_TIME = temp;
}, 3000)
clearInterval(checkTaskId)
}
}, 500)
}
}, 3000)
}, 5000)
global.SAVE_CONST();
};

View File

@ -21,7 +21,8 @@ if (global.TEST_NETWORK) {
MIN_POW_CHAINS = 1;
global.COUNT_NODE_PROOF = 1;
}
var RestStartTime = 0;
var CurAccCount = 0;
export default class CRest extends CDB {
LoadRestContext: LoadContext
LoadHistoryContext: LoadContext
@ -212,6 +213,7 @@ export default class CRest extends CDB {
Context.AccTaskList = []
Context.AccTaskFinished = 0
var AccCount = FindTx.AccountMax + 1;
CurAccCount = AccCount;
for (var n = 0; n < AccCount; n += global.MAX_ACCOUNTS_TRANSFER) {
var Task = { StartNum: n, Count: global.MAX_ACCOUNTS_TRANSFER, Time: 0, MapSend: {} };
if (Task.StartNum + Task.Count > AccCount)
@ -234,6 +236,7 @@ export default class CRest extends CDB {
}
}
Context.Mode++
RestStartTime = Date.now();
global.ToLog("Next mode: " + Context.Mode, 2)
break;
case 6:
@ -248,7 +251,8 @@ export default class CRest extends CDB {
for (var i = 0; i < Context.AccTaskList.length; i++) {
let Task = Context.AccTaskList[i];
var Delta = CurTime - Task.Time;
if (Delta > 5 * 1000 && !Task.OK) {
if (Delta > 1 * 1000 && !Task.OK) {
setTimeout(() => {
var Ret = this.GetNextNode(Task, "", 1);
if (Ret.Result) {
global.ToLog("Send GETREST Num:" + Task.StartNum + "-" + Task.Count + " to " + global.NodeName(Ret.Node), 2)
@ -295,13 +299,14 @@ export default class CRest extends CDB {
Task.OK = true
global.TX_PROCESS.RunRPC("TXWriteAccArr", { StartNum: Task.StartNum, Arr: Data.Arr }, function(Err, Params) {
Context.AccTaskFinished++
global.ToLog(`GETREST ${Context.AccTaskFinished * global.MAX_ACCOUNTS_TRANSFER}/${CurAccCount}(${(Context.AccTaskFinished / Context.AccTaskList.length * 100).toFixed(2)}%) TimeCost: ${Date.now() - RestStartTime}ms`)
})
}
},
})
Task.Time = CurTime
break;
}
}, 0)
}
}
break;