perf: 筛选统计去掉 JSON 兜底,并补上 orders 覆盖索引
去掉 work_orders 堆访问后,JOIN 会把 orders 整表扫进 Hash Right Join。 领取页在快照新鲜时不再打上游;快手出网统一 10 秒超时。倒计时改为自适应间隔。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import test from 'node:test'
|
||||
|
||||
test('快手行业出网调用都走带超时的 fetch 封装', async () => {
|
||||
const http = await readFile(new URL('./http.ts', import.meta.url), 'utf8')
|
||||
assert.ok(http.includes('KUAISHOU_INDUSTRY_HTTP_TIMEOUT_MS = 10_000'))
|
||||
assert.ok(http.includes('AbortSignal.timeout(KUAISHOU_INDUSTRY_HTTP_TIMEOUT_MS)'))
|
||||
assert.ok(http.includes('init?.signal ??'), '调用方已经传入 signal 时不要覆盖,避免打断主动取消')
|
||||
|
||||
for (const file of ['./openapi-client.ts', './token-service.ts']) {
|
||||
const src = await readFile(new URL(file, import.meta.url), 'utf8')
|
||||
assert.ok(src.includes('fetchKuaishouIndustry('), `${file} 仍在直接 fetch`)
|
||||
assert.equal(src.includes('await fetch('), false, `${file} 还有未收口的 fetch`)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,12 @@
|
||||
/** 快手行业出网统一入口。超时收在这里,避免每个调用点各写各的 fetch 再漏掉。 */
|
||||
export const KUAISHOU_INDUSTRY_HTTP_TIMEOUT_MS = 10_000
|
||||
|
||||
export function fetchKuaishouIndustry(
|
||||
input: Parameters<typeof fetch>[0],
|
||||
init?: Parameters<typeof fetch>[1],
|
||||
) {
|
||||
return fetch(input, {
|
||||
...init,
|
||||
signal: init?.signal ?? AbortSignal.timeout(KUAISHOU_INDUSTRY_HTTP_TIMEOUT_MS),
|
||||
})
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { getKuaishouIndustryConfig } from './config.js'
|
||||
import { signKuaishouIndustryPayload, type SignMethod } from './crypto.js'
|
||||
import { fetchKuaishouIndustry } from './http.js'
|
||||
import { ensureKuaishouIndustryAccessToken } from './token-service.js'
|
||||
import { logIntegration } from '../../../utils/logger.js'
|
||||
import type { JsonObject } from '../../../types/json.js'
|
||||
@@ -108,8 +109,8 @@ export async function requestKuaishouIndustryOpenApi(
|
||||
const startedAt = Date.now()
|
||||
const res =
|
||||
httpMethod === 'GET'
|
||||
? await fetch(`${url}?${body.toString()}`, { method: 'GET' })
|
||||
: await fetch(url, {
|
||||
? await fetchKuaishouIndustry(`${url}?${body.toString()}`, { method: 'GET' })
|
||||
: await fetchKuaishouIndustry(url, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
||||
body: body.toString(),
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
type KuaishouIndustryShopConfig,
|
||||
type KuaishouIndustrySourceConfig,
|
||||
} from './source-config-service.js'
|
||||
import { fetchKuaishouIndustry } from './http.js'
|
||||
|
||||
const ACCESS_TOKEN_REFRESH_MARGIN_MS = 30 * 60 * 1000
|
||||
const DEFAULT_ACCESS_TOKEN_TTL_MS = 47 * 60 * 60 * 1000
|
||||
@@ -314,8 +315,8 @@ async function requestKuaishouIndustryToken({
|
||||
const url = new URL(`${baseUrl}${path}`)
|
||||
const response =
|
||||
method === 'GET'
|
||||
? await fetch(appendSearchParams(url, params))
|
||||
: await fetch(url, {
|
||||
? await fetchKuaishouIndustry(appendSearchParams(url, params))
|
||||
: await fetchKuaishouIndustry(url, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
||||
body: params.toString(),
|
||||
|
||||
Reference in New Issue
Block a user