我有关于产品的大量数据,我猜有 140 个字段分成不同的表。
当我选择第一页数据时它工作正常,但是当我选择第 19 或 20 页时,它变得非常慢。
当我请求 Page=1 和 pageSize=100 时,我会在 35 秒内得到响应。
但是当我增加页码时说 19
它在 8 分钟或更长时间内响应。
指导我一些最佳和更专业的方式。
任何提示将不胜感激。
我的 API 处理程序有点像
const page = req.query.page || 1
const pageSize = req.query.pageSize || 30
try {
const data = await BasicProductDetail.findAll({
include: [
{ model: AdditionalProductDetail },
{ model: Catalog },
{ model: ImageDetail },
{ model: Manufacturer },
{ model: Measurement },
{ model: PriceAndCost },
{ model: ProductClass },
{ model: Selling },
{ model: UPC },
{ model: Usage }
],
limit : pageSize,
offset : (page - 1) * pageSize,
order : [ ['id', 'ASC']]
})
const count = await BasicProductDetail.count({ })
res.json({
data: data,
count : count
})
} catch (error) {
console.log(error)
return res.status(500).send(Something Went Wrong!!!)
}
}```
=================================
最佳答案
几个建议。
关于node.js - 我对较大偏移量的 Sequelize 分页响应缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66963779/