perf(cost-center): 商品页跳过无关 affiliate 聚合并补部分索引
This commit is contained in:
@@ -106,6 +106,14 @@ export async function listAdminProducts(payload: JsonObject = {}) {
|
||||
baseClauses.push(productSourceFilterSql(baseParams.length))
|
||||
}
|
||||
|
||||
// 人工/接单平台商品不需要 affiliate 任务统计:跳过 30 天 fulfillment_tasks 聚合。
|
||||
// 只有「全部」和「自动发货」Tab 才需要这条聚合,避免小库 IO 被无关数据拖慢。
|
||||
const needsAffiliateTaskStats = !source || source === 'affiliate_dash'
|
||||
const affiliateTaskJoinSql = needsAffiliateTaskStats ? AFFILIATE_TASK_AGG_JOIN : ''
|
||||
const affiliateColumnsSql = needsAffiliateTaskStats
|
||||
? 'COALESCE(aff.task_count, 0) AS affiliate_task_count, aff.last_fulfilled_at AS affiliate_last_fulfilled_at'
|
||||
: '0::int AS affiliate_task_count, NULL::timestamptz AS affiliate_last_fulfilled_at'
|
||||
|
||||
const categoryId = normalizeCategoryFilter(payload.categoryId ?? payload.category_id)
|
||||
const rootCategoryId = normalizeCategoryFilter(payload.rootCategoryId ?? payload.root_category_id)
|
||||
const listParams = [...baseParams]
|
||||
@@ -196,11 +204,10 @@ export async function listAdminProducts(payload: JsonObject = {}) {
|
||||
LIMIT 1
|
||||
)
|
||||
) AS active_cost_effective_from,
|
||||
COALESCE(aff.task_count, 0) AS affiliate_task_count,
|
||||
aff.last_fulfilled_at AS affiliate_last_fulfilled_at
|
||||
${affiliateColumnsSql}
|
||||
FROM product_catalog p
|
||||
${PRODUCT_CATEGORY_JOINS}
|
||||
${AFFILIATE_TASK_AGG_JOIN}
|
||||
${affiliateTaskJoinSql}
|
||||
${where}
|
||||
ORDER BY
|
||||
p.status ASC,
|
||||
|
||||
Reference in New Issue
Block a user