perf: 支持同步域名过期时间

This commit is contained in:
xiaojunnuo
2026-01-22 00:59:28 +08:00
parent ad64384891
commit a97cee84f3
9 changed files with 319 additions and 99 deletions
@@ -34,3 +34,29 @@ export class Pager {
this.pageNo = Math.ceil(offset / (this.pageSize ?? 50)) + 1;
}
}
export async function doPageTurn<T>(req: { pager: Pager; getPage: (pager: Pager) => Promise<PageRes<T>>; itemHandle?: (item: T) => Promise<void>; batchHandle?: (pageRes: PageRes<T>) => Promise<void> }) {
let count = 0;
const { pager, getPage, itemHandle, batchHandle } = req;
while (true) {
const pageRes = await getPage(pager);
if (!pageRes || !pageRes.list || pageRes.list.length === 0) {
break;
}
count += pageRes.list.length;
if (batchHandle) {
await batchHandle(pageRes);
}
if (itemHandle) {
for (const item of pageRes.list) {
await itemHandle(item);
}
}
if (pageRes.total && pageRes.total >= 0 && count >= pageRes.total) {
//遍历完成
break;
}
pager.pageNo++;
}
return count;
}