订单详情效率优化
This commit is contained in:
@@ -719,6 +719,7 @@ async function syncCustomerDetails(page, options = {}) {
|
||||
console.log(`[客户详情] 共 ${customerTargets.length} 个客户需要获取详情`);
|
||||
const allDetails = Array.isArray(resumeCheckpoint?.records) ? resumeCheckpoint.records : [];
|
||||
let currentListPage = 0;
|
||||
let currentGroupKey = '';
|
||||
let startIndex = Number.parseInt(String(resumeCheckpoint?.currentIndex || 0), 10) || 0;
|
||||
if (startIndex > 0) {
|
||||
console.log(`[客户详情续爬] 从 checkpoint 恢复: index=${startIndex}, records=${allDetails.length}`);
|
||||
@@ -745,6 +746,11 @@ async function syncCustomerDetails(page, options = {}) {
|
||||
currentListPage = target.pageNum;
|
||||
}
|
||||
|
||||
const nextGroupKey = `${target.pageNum}`;
|
||||
if (currentGroupKey !== nextGroupKey) {
|
||||
currentGroupKey = nextGroupKey;
|
||||
}
|
||||
|
||||
const clicked = await clickCustomerDetailFromListWithRetry(page, target);
|
||||
if (!clicked) {
|
||||
console.warn(`[客户详情] 列表中未找到 accountId=${target.accountId},跳过`);
|
||||
@@ -761,7 +767,7 @@ async function syncCustomerDetails(page, options = {}) {
|
||||
} catch {
|
||||
console.warn(`[客户详情] ${target.accountId} 详情页加载超时,跳过`);
|
||||
await page.goBack({ waitUntil: 'domcontentloaded' }).catch(() => null);
|
||||
await recoverCustomerListState(page, currentListPage).catch(() => null);
|
||||
await waitForStableCustomerList(page).catch(() => null);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -774,7 +780,7 @@ async function syncCustomerDetails(page, options = {}) {
|
||||
}
|
||||
|
||||
await page.goBack({ waitUntil: 'domcontentloaded' }).catch(() => null);
|
||||
await recoverCustomerListState(page, currentListPage).catch(() => null);
|
||||
await waitForStableCustomerList(page).catch(() => null);
|
||||
currentListPage = target.pageNum;
|
||||
}
|
||||
|
||||
@@ -1353,6 +1359,7 @@ async function syncOrderDetails(page, cachedOrderIds, options = {}) {
|
||||
}
|
||||
let currentListPage = 0;
|
||||
let currentWindowKey = '';
|
||||
let currentGroupKey = '';
|
||||
|
||||
await page.goto(datasets.orders.url, { waitUntil: 'domcontentloaded' });
|
||||
await waitUntilReady(page, datasets.orders.heading);
|
||||
@@ -1370,7 +1377,8 @@ async function syncOrderDetails(page, cachedOrderIds, options = {}) {
|
||||
currentListPage = 1;
|
||||
}
|
||||
|
||||
if (target.pageNum > 0 && currentListPage !== target.pageNum) {
|
||||
const nextGroupKey = `${nextWindowKey}|${target.pageNum}`;
|
||||
if (target.pageNum > 0 && (currentListPage !== target.pageNum || currentGroupKey !== nextGroupKey)) {
|
||||
const reached = await jumpToOrderPage(page, target.pageNum);
|
||||
if (!reached) {
|
||||
console.warn(`[订单详情] 无法跳到第 ${target.pageNum} 页,跳过 ${target.orderId}`);
|
||||
@@ -1378,6 +1386,7 @@ async function syncOrderDetails(page, cachedOrderIds, options = {}) {
|
||||
}
|
||||
currentListPage = target.pageNum;
|
||||
}
|
||||
currentGroupKey = nextGroupKey;
|
||||
|
||||
const clicked = await clickOrderDetailFromListWithRetry(page, target);
|
||||
if (!clicked) {
|
||||
@@ -1395,7 +1404,7 @@ async function syncOrderDetails(page, cachedOrderIds, options = {}) {
|
||||
} catch {
|
||||
console.warn(`[订单详情] ${target.orderId} 详情页加载超时,跳过`);
|
||||
await page.goBack({ waitUntil: 'domcontentloaded' }).catch(() => null);
|
||||
await recoverOrderListState(page, currentListPage).catch(() => null);
|
||||
await waitForStableOrderList(page).catch(() => null);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1411,7 +1420,7 @@ async function syncOrderDetails(page, cachedOrderIds, options = {}) {
|
||||
}
|
||||
|
||||
await page.goBack({ waitUntil: 'domcontentloaded' }).catch(() => null);
|
||||
await recoverOrderListState(page, currentListPage, target.windowStart, target.windowEnd).catch(() => null);
|
||||
await waitForStableOrderList(page).catch(() => null);
|
||||
currentListPage = target.pageNum;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user