perf: 筛选统计去掉 JSON 兜底,并补上 orders 覆盖索引
去掉 work_orders 堆访问后,JOIN 会把 orders 整表扫进 Hash Right Join。 领取页在快照新鲜时不再打上游;快手出网统一 10 秒超时。倒计时改为自适应间隔。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2,8 +2,11 @@ import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
|
||||
import {
|
||||
AFFILIATE_DASH_BIND_REFRESH_FRESH_MS,
|
||||
AFFILIATE_DASH_ORDER_SYNC_FRESH_MS,
|
||||
canReuseAffiliateDashBindSnapshot,
|
||||
isAffiliateDashBindSnapshotStale,
|
||||
isAffiliateDashSnapshotFresh,
|
||||
shouldRefreshAffiliateDashBindStateForSnapshot,
|
||||
} from './kuaishou-cloud-claim-service.js'
|
||||
|
||||
@@ -138,6 +141,84 @@ test('canReuseAffiliateDashBindSnapshot refuses mismatched bound account', () =>
|
||||
)
|
||||
})
|
||||
|
||||
test('isAffiliateDashSnapshotFresh treats missing or future timestamps as stale', () => {
|
||||
const now = Date.parse('2026-10-01T06:00:00.000Z')
|
||||
assert.equal(isAffiliateDashSnapshotFresh(null, AFFILIATE_DASH_ORDER_SYNC_FRESH_MS, now), false)
|
||||
assert.equal(isAffiliateDashSnapshotFresh('', AFFILIATE_DASH_ORDER_SYNC_FRESH_MS, now), false)
|
||||
assert.equal(
|
||||
isAffiliateDashSnapshotFresh('not-a-date', AFFILIATE_DASH_ORDER_SYNC_FRESH_MS, now),
|
||||
false,
|
||||
)
|
||||
assert.equal(
|
||||
isAffiliateDashSnapshotFresh(
|
||||
'2026-10-01T06:00:01.000Z',
|
||||
AFFILIATE_DASH_ORDER_SYNC_FRESH_MS,
|
||||
now,
|
||||
),
|
||||
false,
|
||||
)
|
||||
})
|
||||
|
||||
test('order snapshot stays fresh for 45s and bind snapshot only for 15s', () => {
|
||||
const now = Date.parse('2026-10-01T06:00:45.000Z')
|
||||
assert.equal(
|
||||
isAffiliateDashSnapshotFresh(
|
||||
'2026-10-01T06:00:00.000Z',
|
||||
AFFILIATE_DASH_ORDER_SYNC_FRESH_MS,
|
||||
now,
|
||||
),
|
||||
false,
|
||||
)
|
||||
assert.equal(
|
||||
isAffiliateDashSnapshotFresh(
|
||||
'2026-10-01T06:00:01.000Z',
|
||||
AFFILIATE_DASH_ORDER_SYNC_FRESH_MS,
|
||||
now,
|
||||
),
|
||||
true,
|
||||
)
|
||||
assert.equal(
|
||||
isAffiliateDashSnapshotFresh(
|
||||
'2026-10-01T06:00:30.000Z',
|
||||
AFFILIATE_DASH_BIND_REFRESH_FRESH_MS,
|
||||
now,
|
||||
),
|
||||
false,
|
||||
)
|
||||
assert.equal(
|
||||
isAffiliateDashSnapshotFresh(
|
||||
'2026-10-01T06:00:31.000Z',
|
||||
AFFILIATE_DASH_BIND_REFRESH_FRESH_MS,
|
||||
now,
|
||||
),
|
||||
true,
|
||||
)
|
||||
})
|
||||
|
||||
test('claim detail skips affiliate-dash sync while the snapshot is fresh', async () => {
|
||||
const { readFile } = await import('node:fs/promises')
|
||||
const src = await readFile(new URL('./kuaishou-cloud-claim-service.ts', import.meta.url), 'utf8')
|
||||
const detail = src.slice(
|
||||
src.indexOf('export async function getKuaishouCloudClaimDetail'),
|
||||
src.indexOf('export async function submitClaimUid'),
|
||||
)
|
||||
assert.ok(detail.includes('flow.mock?.enabled'))
|
||||
assert.ok(detail.includes('isAffiliateDashSnapshotFresh(flow.lastSyncedAt'))
|
||||
assert.ok(detail.includes('bindFlow.lastBindSyncedAt'))
|
||||
assert.ok(
|
||||
!detail.includes('snapshotOnly'),
|
||||
'新鲜快照必须直接不调用同步;snapshotOnly 仍会 updateTask',
|
||||
)
|
||||
const refresh = src.slice(
|
||||
src.indexOf('async function refreshAffiliateDashBindState'),
|
||||
src.indexOf('function normalizeUid'),
|
||||
)
|
||||
assert.ok(
|
||||
refresh.includes('lastBindSyncedAt: now'),
|
||||
'成功拉取绑定结果后才记时间,失败不能挡住下一次',
|
||||
)
|
||||
})
|
||||
|
||||
test('shouldRefreshAffiliateDashBindStateForSnapshot keeps polling before submit', () => {
|
||||
assert.equal(
|
||||
shouldRefreshAffiliateDashBindStateForSnapshot({
|
||||
|
||||
Reference in New Issue
Block a user