【发布时间】:2020-03-11 12:38:30
【问题描述】:
这两个代码块之间是否有任何性能变化
const supplier = await Supplier.query()
.findById(1)
.throwIfNotFound()
await supplier.$query().delete()
await Supplier.query().findById(1).throwIfNotFound().delete()
据我了解,第二个代码更好,因为只有一个等待代码块 不像第一个有两个异步方法。但是对于第一块代码中的这个例子,由于执行速度很快,所以 await 方法不会暂停 find 查询,而是两个方法都立即继续执行。
这个评估是否正确?如果不是,哪个更好?
【问题讨论】: