perf(P22PROD1-3,P22PROD1-4): 资产exact-first搜索优化与三条benchmark脚本
这个提交包含在:
+48
-22
@@ -837,42 +837,68 @@ async function assetsRoutes(fastify) {
|
||||
ensureAssetReadPermission(fastify, request);
|
||||
const query = parseAssetListQuery(request.query);
|
||||
const mine = !canViewAllAssets(fastify, request.employee) || query.mine === true;
|
||||
const where = {};
|
||||
const baseWhere = {};
|
||||
if (query.status) {
|
||||
where.status = query.status;
|
||||
baseWhere.status = query.status;
|
||||
}
|
||||
if (query.categoryId) {
|
||||
where.category_id = query.categoryId;
|
||||
baseWhere.category_id = query.categoryId;
|
||||
}
|
||||
if (query.legalEntityId) {
|
||||
where.legal_entity_id = query.legalEntityId;
|
||||
baseWhere.legal_entity_id = query.legalEntityId;
|
||||
}
|
||||
if (query.costCenterId) {
|
||||
where.cost_center_id = query.costCenterId;
|
||||
}
|
||||
if (query.q) {
|
||||
where.OR = [
|
||||
{ asset_no: query.q },
|
||||
{ serial_no: query.q },
|
||||
{
|
||||
name: {
|
||||
contains: query.q,
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
];
|
||||
baseWhere.cost_center_id = query.costCenterId;
|
||||
}
|
||||
if (mine) {
|
||||
where.assignee_employee_id = request.employee.id;
|
||||
baseWhere.assignee_employee_id = request.employee.id;
|
||||
} else if (query.assigneeId) {
|
||||
where.assignee_employee_id = query.assigneeId;
|
||||
baseWhere.assignee_employee_id = query.assigneeId;
|
||||
}
|
||||
|
||||
const items = await fastify.prisma.assetCard.findMany({
|
||||
where,
|
||||
const listOptions = {
|
||||
orderBy: [{ updated_at: "desc" }, { created_at: "desc" }],
|
||||
select: ASSET_CARD_SELECT,
|
||||
});
|
||||
};
|
||||
|
||||
let items;
|
||||
if (query.q) {
|
||||
items = await fastify.prisma.assetCard.findMany({
|
||||
where: {
|
||||
...baseWhere,
|
||||
asset_no: query.q,
|
||||
},
|
||||
...listOptions,
|
||||
});
|
||||
|
||||
if (!items.length) {
|
||||
items = await fastify.prisma.assetCard.findMany({
|
||||
where: {
|
||||
...baseWhere,
|
||||
serial_no: query.q,
|
||||
},
|
||||
...listOptions,
|
||||
});
|
||||
}
|
||||
|
||||
if (!items.length) {
|
||||
items = await fastify.prisma.assetCard.findMany({
|
||||
where: {
|
||||
...baseWhere,
|
||||
name: {
|
||||
contains: query.q,
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
...listOptions,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
items = await fastify.prisma.assetCard.findMany({
|
||||
where: baseWhere,
|
||||
...listOptions,
|
||||
});
|
||||
}
|
||||
|
||||
return sendData(reply, request, {
|
||||
mine,
|
||||
|
||||
在新工单中引用
屏蔽一个用户