改用订单刷新复合游标扫描
This commit is contained in:
1 parent
c27db2381b
commit
c30029557c
6 files changed
+90
-9
No files matched your search
@@ -224,10 +224,10 @@ func (r storeOrderRepository) SoftDeleteMissingOrders(ctx context.Context, cooki
|
||||
return r.store.Orders.SoftDeleteMissingForCookie(ctx, cookieID, activeIDs)
|
||||
}
|
||||
|
||||
// ListOrdersByCookiePage 委托账号订单分页查询。
|
||||
func (r storeOrderRepository) ListOrdersByCookiePage(ctx context.Context, cookieID string, limit, offset int) ([]orderapp.OrderRow, error) {
|
||||
// rows 和 err 保存数据库订单分页结果及其错误。
|
||||
rows, err := r.store.Orders.ByCookiePage(ctx, cookieID, limit, offset)
|
||||
// ListOrdersByCookieCursor 委托订单复合游标查询并转换应用层模型。
|
||||
func (r storeOrderRepository) ListOrdersByCookieCursor(ctx context.Context, cookieID string, limit int, afterCreatedAt, afterOrderID string) ([]orderapp.OrderRow, error) {
|
||||
// rows、err 保存数据库游标查询结果及错误。
|
||||
rows, err := r.store.Orders.ByCookieCursor(ctx, cookieID, limit, afterCreatedAt, afterOrderID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -951,10 +951,11 @@ func (a *orderApplicationService) Refresh(ctx context.Context, userID int64, coo
|
||||
if _, blocked := sessionExpiredAccounts[cid]; blocked {
|
||||
continue
|
||||
}
|
||||
for // offset 保存偏移量,供当前处理流程使用
|
||||
offset := 0; ; offset += 500 {
|
||||
// afterCreatedAt、afterOrderID 保存当前账号订单扫描游标。
|
||||
afterCreatedAt, afterOrderID := "", ""
|
||||
for {
|
||||
// rows、err 保存rows、err,供当前处理流程使用
|
||||
rows, err := a.repository.ListOrdersByCookiePage(ctx, cid, 500, offset)
|
||||
rows, err := a.repository.ListOrdersByCookieCursor(ctx, cid, 500, afterCreatedAt, afterOrderID)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
@@ -975,6 +976,12 @@ func (a *orderApplicationService) Refresh(ctx context.Context, userID int64, coo
|
||||
if len(rows) < 500 {
|
||||
break
|
||||
}
|
||||
// lastRow 保存本页最后一条订单,用于推进下一页复合游标。
|
||||
lastRow := rows[len(rows)-1]
|
||||
if lastRow.CreatedAt == afterCreatedAt && lastRow.OrderID == afterOrderID {
|
||||
break
|
||||
}
|
||||
afterCreatedAt, afterOrderID = lastRow.CreatedAt, lastRow.OrderID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user