前言:实现完rpc接口后,开始进行性能优化,提升响应效率。
1,查全量表,如果表格几万条,甚至更多信息时,导致性能下降。
// const tickInfos = await knex(SRC20_TICK_TABLE); // const tickInfoMap = {} // for (let item of tickInfos) { // tickInfoMap[item.tick] = item // }解决办法,应该加where条件。
const res = await knex(SRC20_VALID_TABLE).whereIn('tx_hash', [params.tx_hash]) const resArr = [] for (let each of res) { const tickInfoArr = await knex(SRC20_TICK_TABLE).whereIn("id", [each.tick]); if (!tickInfoArr.length) { throw new Error("tick not found") } const dec = tickInfoArr[0].dec || 18 resArr.push({ op: each.op, tick: each.tick, max: toNonExponential(new Decimal(tickInfoArr[0].max).mul(new Decimal(10**dec))) || "18446744073709551615", // uint64_max lim: toNonExponential(new Decimal(tickInfoArr[0].lim).mul(new Decimal(10**dec))) || "18446744073709551615", // uint64_max amt: (each.op === 'deploy' ? 0 : toNonExponential(new Decimal(each.amt).mul(new Decimal(10**dec)))) || new Decimal(0), // 0 dec: dec, from: each.sender || "", to: each.creator || "", valid: true, msg: "ok" }) }
2,
标签:tickInfoArr,const,性能,sql,each,new,dec,优化,Decimal From: https://www.cnblogs.com/zccst/p/17935486.html