@pisell/pisellos 2.3.2 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/Order/index.js +0 -2
- package/dist/server/index.js +0 -1
- package/dist/server/modules/order/index.d.ts +25 -7
- package/dist/server/modules/order/index.js +370 -309
- package/lib/modules/Order/index.js +0 -2
- package/lib/server/modules/order/index.d.ts +25 -7
- package/lib/server/modules/order/index.js +88 -54
- package/package.json +1 -1
|
@@ -49,6 +49,13 @@ var ORDER_SILENT_REFRESH_MIN_INTERVAL_MS = 30000;
|
|
|
49
49
|
/** 视为「业务侧刚写入」的来源,pubsub 回声可跳过 SQLite */
|
|
50
50
|
var ORDER_BUSINESS_WRITE_SOURCES = new Set(['upsertOrdersFromRemote', 'upsertPendingSyncOrders', 'overwriteExistingOrder', 'markOrderSyncedByExternalSaleNumber']);
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* 合并热路径全表去重自检开关:默认关闭。
|
|
54
|
+
* 开启后每次合并会额外对整张 store 做一次 O(n^2) 重复检测并告警,
|
|
55
|
+
* 仅用于排查增量身份索引是否遗漏了重复订单,不应在生产常开。
|
|
56
|
+
*/
|
|
57
|
+
var ORDER_MERGE_SELF_CHECK = false;
|
|
58
|
+
|
|
52
59
|
/**
|
|
53
60
|
* Order 模块 - 基础框架
|
|
54
61
|
*/
|
|
@@ -68,8 +75,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
68
75
|
_defineProperty(_assertThisInitialized(_this), "syncTimer", void 0);
|
|
69
76
|
_defineProperty(_assertThisInitialized(_this), "isProcessingSyncBatch", false);
|
|
70
77
|
_defineProperty(_assertThisInitialized(_this), "isIdlePhase", true);
|
|
71
|
-
// Map<resource_id, OrderId[]> 资源到订单的倒排索引
|
|
72
|
-
_defineProperty(_assertThisInitialized(_this), "resourceIdIndex", new Map());
|
|
73
78
|
_defineProperty(_assertThisInitialized(_this), "logger", void 0);
|
|
74
79
|
// LoggerManager 实例
|
|
75
80
|
_defineProperty(_assertThisInitialized(_this), "storage", void 0);
|
|
@@ -172,10 +177,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
172
177
|
return initialize;
|
|
173
178
|
}()
|
|
174
179
|
/**
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
180
|
+
* 记录信息日志
|
|
181
|
+
* @param title 日志标题
|
|
182
|
+
* @param metadata 日志元数据
|
|
183
|
+
*/
|
|
179
184
|
}, {
|
|
180
185
|
key: "logInfo",
|
|
181
186
|
value: function logInfo(title, metadata) {
|
|
@@ -774,17 +779,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
774
779
|
}
|
|
775
780
|
return silentRefresh;
|
|
776
781
|
}())
|
|
777
|
-
}, {
|
|
778
|
-
key: "getOrdersByResourceId",
|
|
779
|
-
value: function getOrdersByResourceId(resourceId) {
|
|
780
|
-
var _this8 = this;
|
|
781
|
-
var ids = this.resourceIdIndex.get(String(resourceId)) || [];
|
|
782
|
-
return ids.map(function (id) {
|
|
783
|
-
return _this8.store.map.get(id);
|
|
784
|
-
}).filter(function (order) {
|
|
785
|
-
return !!order;
|
|
786
|
-
});
|
|
787
|
-
}
|
|
788
782
|
}, {
|
|
789
783
|
key: "normalizeOrderForMemoryList",
|
|
790
784
|
value: function normalizeOrderForMemoryList(order) {
|
|
@@ -808,7 +802,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
808
802
|
key: "overwriteExistingOrder",
|
|
809
803
|
value: (function () {
|
|
810
804
|
var _overwriteExistingOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(fresh) {
|
|
811
|
-
var
|
|
805
|
+
var _this8 = this;
|
|
812
806
|
var orderId, key;
|
|
813
807
|
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
814
808
|
while (1) switch (_context8.prev = _context8.next) {
|
|
@@ -842,7 +836,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
842
836
|
this.store.list = this.store.list.map(function (order) {
|
|
843
837
|
var id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
844
838
|
if (id === undefined || id === null) return order;
|
|
845
|
-
return
|
|
839
|
+
return _this8.getIdKey(id) === key ? fresh : order;
|
|
846
840
|
});
|
|
847
841
|
this.syncOrdersMap();
|
|
848
842
|
_context8.next = 13;
|
|
@@ -908,7 +902,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
908
902
|
key: "markOrderSyncedByExternalSaleNumber",
|
|
909
903
|
value: function () {
|
|
910
904
|
var _markOrderSyncedByExternalSaleNumber = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
|
|
911
|
-
var
|
|
905
|
+
var _this9 = this,
|
|
912
906
|
_existing$external_sa,
|
|
913
907
|
_nextOrder$order_id;
|
|
914
908
|
var externalSaleNumber, key, targetIndex, existing, nextOrder, storageKey;
|
|
@@ -929,7 +923,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
929
923
|
targetIndex = this.store.list.findIndex(function (order) {
|
|
930
924
|
var value = order === null || order === void 0 ? void 0 : order.external_sale_number;
|
|
931
925
|
if (value === undefined || value === null || value === '') return false;
|
|
932
|
-
return
|
|
926
|
+
return _this9.getIdKey(value) === key;
|
|
933
927
|
});
|
|
934
928
|
if (!(targetIndex < 0)) {
|
|
935
929
|
_context10.next = 9;
|
|
@@ -986,7 +980,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
986
980
|
key: "upsertPendingSyncOrders",
|
|
987
981
|
value: (function () {
|
|
988
982
|
var _upsertPendingSyncOrders = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(pendingOrders) {
|
|
989
|
-
var pendingMap, memoryPendingMap, _iterator4, _step4, order, storageKey, patchedOrders, mergeActions, updatedList,
|
|
983
|
+
var pendingMap, memoryPendingMap, _iterator4, _step4, order, storageKey, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, _iterator5, _step5, key, _iterator6, _step6, _step6$value, _storageKey, pendingOrder, matchIndex, mergedOrder, insertIndex;
|
|
990
984
|
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
991
985
|
while (1) switch (_context11.prev = _context11.next) {
|
|
992
986
|
case 0:
|
|
@@ -1046,72 +1040,82 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1046
1040
|
});
|
|
1047
1041
|
patchedOrders = _toConsumableArray(pendingMap.values());
|
|
1048
1042
|
mergeActions = {};
|
|
1049
|
-
updatedList = _toConsumableArray(this.store.list);
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1043
|
+
updatedList = _toConsumableArray(this.store.list); // 与 mergeOrdersToStore 一致:基于身份键(field:value)建立索引,把「查找已存在订单」
|
|
1044
|
+
// 从 O(n) 线性扫描降为 O(1),整体复杂度由 O(n^2) 降为 O(n + m)。
|
|
1045
|
+
identityKeyToIndex = new Map();
|
|
1046
|
+
for (index = 0; index < updatedList.length; index += 1) {
|
|
1047
|
+
_iterator5 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(updatedList[index]));
|
|
1048
|
+
try {
|
|
1049
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
1050
|
+
key = _step5.value;
|
|
1051
|
+
// 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
|
|
1052
|
+
if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
|
|
1053
|
+
}
|
|
1054
|
+
} catch (err) {
|
|
1055
|
+
_iterator5.e(err);
|
|
1056
|
+
} finally {
|
|
1057
|
+
_iterator5.f();
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
_iterator6 = _createForOfIteratorHelper(memoryPendingMap.entries());
|
|
1061
|
+
_context11.prev = 35;
|
|
1062
|
+
_iterator6.s();
|
|
1063
|
+
case 37:
|
|
1064
|
+
if ((_step6 = _iterator6.n()).done) {
|
|
1065
|
+
_context11.next = 52;
|
|
1056
1066
|
break;
|
|
1057
1067
|
}
|
|
1058
|
-
|
|
1059
|
-
matchIndex = this.
|
|
1060
|
-
if (!(matchIndex
|
|
1061
|
-
_context11.next =
|
|
1068
|
+
_step6$value = _slicedToArray(_step6.value, 2), _storageKey = _step6$value[0], pendingOrder = _step6$value[1];
|
|
1069
|
+
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, this.getOrderIdentityMatchKeys(pendingOrder));
|
|
1070
|
+
if (!(matchIndex >= 0)) {
|
|
1071
|
+
_context11.next = 46;
|
|
1062
1072
|
break;
|
|
1063
1073
|
}
|
|
1064
|
-
|
|
1065
|
-
case 40:
|
|
1066
|
-
updatedList[matchIndex] = this.mergeOrderRecords(updatedList[matchIndex], pendingOrder, {
|
|
1074
|
+
mergedOrder = this.mergeOrderRecords(updatedList[matchIndex], pendingOrder, {
|
|
1067
1075
|
preferIncomingProducts: true
|
|
1068
1076
|
});
|
|
1069
|
-
|
|
1070
|
-
|
|
1077
|
+
updatedList[matchIndex] = mergedOrder;
|
|
1078
|
+
// 合并后身份字段可能新增(如挂单拿到 order_id),同步登记,供同批后续 pending 命中同一槽位
|
|
1079
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex);
|
|
1071
1080
|
mergeActions[_storageKey] = 'update';
|
|
1072
|
-
|
|
1073
|
-
_context11.next = 35;
|
|
1074
|
-
break;
|
|
1081
|
+
return _context11.abrupt("continue", 50);
|
|
1075
1082
|
case 46:
|
|
1076
|
-
|
|
1083
|
+
insertIndex = updatedList.length;
|
|
1084
|
+
updatedList.push(pendingOrder);
|
|
1085
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, pendingOrder, insertIndex);
|
|
1086
|
+
mergeActions[_storageKey] = 'insert';
|
|
1087
|
+
case 50:
|
|
1088
|
+
_context11.next = 37;
|
|
1089
|
+
break;
|
|
1090
|
+
case 52:
|
|
1091
|
+
_context11.next = 57;
|
|
1077
1092
|
break;
|
|
1078
|
-
case 48:
|
|
1079
|
-
_context11.prev = 48;
|
|
1080
|
-
_context11.t1 = _context11["catch"](33);
|
|
1081
|
-
_iterator5.e(_context11.t1);
|
|
1082
|
-
case 51:
|
|
1083
|
-
_context11.prev = 51;
|
|
1084
|
-
_iterator5.f();
|
|
1085
|
-
return _context11.finish(51);
|
|
1086
1093
|
case 54:
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
_iterator6.f();
|
|
1098
|
-
}
|
|
1099
|
-
this.store.list = this.compactOrderListByIdentity(updatedList, 'upsertPendingSyncOrders.store').list;
|
|
1094
|
+
_context11.prev = 54;
|
|
1095
|
+
_context11.t1 = _context11["catch"](35);
|
|
1096
|
+
_iterator6.e(_context11.t1);
|
|
1097
|
+
case 57:
|
|
1098
|
+
_context11.prev = 57;
|
|
1099
|
+
_iterator6.f();
|
|
1100
|
+
return _context11.finish(57);
|
|
1101
|
+
case 60:
|
|
1102
|
+
// 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;仅自检开关开启时兜底。
|
|
1103
|
+
this.store.list = this.runOrderStoreSelfCheck(updatedList, 'upsertPendingSyncOrders.store');
|
|
1100
1104
|
this.syncOrdersMap();
|
|
1101
|
-
_context11.next =
|
|
1105
|
+
_context11.next = 64;
|
|
1102
1106
|
return this.patchOrdersInSQLite(patchedOrders, 'upsertPendingSyncOrders', mergeActions);
|
|
1103
|
-
case
|
|
1107
|
+
case 64:
|
|
1104
1108
|
this.logInfo('upsertPendingSyncOrders-结束', {
|
|
1105
1109
|
count: patchedOrders.length,
|
|
1106
1110
|
storeOrderCountAfter: this.store.list.length
|
|
1107
1111
|
});
|
|
1108
|
-
_context11.next =
|
|
1112
|
+
_context11.next = 67;
|
|
1109
1113
|
return this.emitOrdersChanged(patchedOrders, 'upsertPendingSyncOrders');
|
|
1110
|
-
case
|
|
1114
|
+
case 67:
|
|
1111
1115
|
case "end":
|
|
1112
1116
|
return _context11.stop();
|
|
1113
1117
|
}
|
|
1114
|
-
}, _callee11, this, [[6, 19, 22, 25], [
|
|
1118
|
+
}, _callee11, this, [[6, 19, 22, 25], [35, 54, 57, 60]]);
|
|
1115
1119
|
}));
|
|
1116
1120
|
function upsertPendingSyncOrders(_x7) {
|
|
1117
1121
|
return _upsertPendingSyncOrders.apply(this, arguments);
|
|
@@ -1188,39 +1192,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1188
1192
|
}, {
|
|
1189
1193
|
key: "syncOrdersMap",
|
|
1190
1194
|
value: function syncOrdersMap() {
|
|
1191
|
-
var _this11 = this;
|
|
1192
1195
|
this.store.map.clear();
|
|
1193
|
-
this.resourceIdIndex.clear();
|
|
1194
1196
|
var _iterator7 = _createForOfIteratorHelper(this.store.list),
|
|
1195
1197
|
_step7;
|
|
1196
1198
|
try {
|
|
1197
|
-
var _loop = function _loop() {
|
|
1198
|
-
var order = _step7.value;
|
|
1199
|
-
var primaryIdentity = _this11.getOrderMapKey(order);
|
|
1200
|
-
if (!primaryIdentity) return 1; // continue
|
|
1201
|
-
_this11.store.map.set(primaryIdentity, order);
|
|
1202
|
-
var resourceIds = _this11.extractResourceIds(order);
|
|
1203
|
-
var _iterator8 = _createForOfIteratorHelper(resourceIds),
|
|
1204
|
-
_step8;
|
|
1205
|
-
try {
|
|
1206
|
-
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1207
|
-
var resourceId = _step8.value;
|
|
1208
|
-
var key = String(resourceId);
|
|
1209
|
-
var existing = _this11.resourceIdIndex.get(key) || [];
|
|
1210
|
-
if (existing.some(function (eid) {
|
|
1211
|
-
return _this11.getIdKey(eid) === primaryIdentity;
|
|
1212
|
-
})) continue;
|
|
1213
|
-
existing.push(primaryIdentity);
|
|
1214
|
-
_this11.resourceIdIndex.set(key, existing);
|
|
1215
|
-
}
|
|
1216
|
-
} catch (err) {
|
|
1217
|
-
_iterator8.e(err);
|
|
1218
|
-
} finally {
|
|
1219
|
-
_iterator8.f();
|
|
1220
|
-
}
|
|
1221
|
-
};
|
|
1222
1199
|
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
1223
|
-
|
|
1200
|
+
var order = _step7.value;
|
|
1201
|
+
var primaryIdentity = this.getOrderMapKey(order);
|
|
1202
|
+
if (!primaryIdentity) continue;
|
|
1203
|
+
this.store.map.set(primaryIdentity, order);
|
|
1224
1204
|
}
|
|
1225
1205
|
} catch (err) {
|
|
1226
1206
|
_iterator7.e(err);
|
|
@@ -1249,7 +1229,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1249
1229
|
}, {
|
|
1250
1230
|
key: "getOrderIdentityEntries",
|
|
1251
1231
|
value: function getOrderIdentityEntries(order) {
|
|
1252
|
-
var
|
|
1232
|
+
var _this10 = this;
|
|
1253
1233
|
if (!order) return [];
|
|
1254
1234
|
var record = order;
|
|
1255
1235
|
var candidates = [{
|
|
@@ -1266,10 +1246,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1266
1246
|
value: record.shop_order_number
|
|
1267
1247
|
}];
|
|
1268
1248
|
var entries = [];
|
|
1269
|
-
var
|
|
1249
|
+
var _loop = function _loop() {
|
|
1270
1250
|
var candidate = _candidates[_i];
|
|
1271
|
-
if (
|
|
1272
|
-
var key =
|
|
1251
|
+
if (_this10.isBlankIdentityValue(candidate.value)) return 0; // continue
|
|
1252
|
+
var key = _this10.getIdKey(candidate.value);
|
|
1273
1253
|
if (entries.some(function (entry) {
|
|
1274
1254
|
return entry.field === candidate.field && entry.key === key;
|
|
1275
1255
|
})) return 0; // continue
|
|
@@ -1280,7 +1260,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1280
1260
|
},
|
|
1281
1261
|
_ret;
|
|
1282
1262
|
for (var _i = 0, _candidates = candidates; _i < _candidates.length; _i++) {
|
|
1283
|
-
_ret =
|
|
1263
|
+
_ret = _loop();
|
|
1284
1264
|
if (_ret === 0) continue;
|
|
1285
1265
|
}
|
|
1286
1266
|
return entries;
|
|
@@ -1289,39 +1269,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1289
1269
|
key: "getOrderIdentityKeys",
|
|
1290
1270
|
value: function getOrderIdentityKeys(order) {
|
|
1291
1271
|
var keys = [];
|
|
1292
|
-
var
|
|
1293
|
-
|
|
1272
|
+
var _iterator8 = _createForOfIteratorHelper(this.getOrderIdentityEntries(order)),
|
|
1273
|
+
_step8;
|
|
1294
1274
|
try {
|
|
1295
|
-
for (
|
|
1296
|
-
var entry =
|
|
1275
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
1276
|
+
var entry = _step8.value;
|
|
1297
1277
|
if (!keys.includes(entry.key)) keys.push(entry.key);
|
|
1298
1278
|
}
|
|
1299
1279
|
} catch (err) {
|
|
1300
|
-
|
|
1280
|
+
_iterator8.e(err);
|
|
1301
1281
|
} finally {
|
|
1302
|
-
|
|
1282
|
+
_iterator8.f();
|
|
1303
1283
|
}
|
|
1304
1284
|
return keys;
|
|
1305
1285
|
}
|
|
1306
|
-
}, {
|
|
1307
|
-
key: "extractResourceIds",
|
|
1308
|
-
value: function extractResourceIds(order) {
|
|
1309
|
-
var ids = new Set();
|
|
1310
|
-
var visitResources = function visitResources(resources) {
|
|
1311
|
-
if (!Array.isArray(resources)) return;
|
|
1312
|
-
resources.forEach(function (resource) {
|
|
1313
|
-
var rid = resource === null || resource === void 0 ? void 0 : resource.relation_id;
|
|
1314
|
-
if (rid !== undefined && rid !== null && rid !== '') ids.add(String(rid));
|
|
1315
|
-
if (Array.isArray(resource === null || resource === void 0 ? void 0 : resource.children)) visitResources(resource.children);
|
|
1316
|
-
});
|
|
1317
|
-
};
|
|
1318
|
-
if (Array.isArray(order === null || order === void 0 ? void 0 : order.bookings)) {
|
|
1319
|
-
order.bookings.forEach(function (booking) {
|
|
1320
|
-
return visitResources((booking === null || booking === void 0 ? void 0 : booking.resources) || []);
|
|
1321
|
-
});
|
|
1322
|
-
}
|
|
1323
|
-
return _toConsumableArray(ids);
|
|
1324
|
-
}
|
|
1325
1286
|
}, {
|
|
1326
1287
|
key: "getOrderDateKey",
|
|
1327
1288
|
value: function getOrderDateKey(order) {
|
|
@@ -1355,7 +1316,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1355
1316
|
}, {
|
|
1356
1317
|
key: "setupOrderSync",
|
|
1357
1318
|
value: function setupOrderSync() {
|
|
1358
|
-
var
|
|
1319
|
+
var _this11 = this;
|
|
1359
1320
|
if (!this.orderDataSource) return;
|
|
1360
1321
|
this.orderDataSource.run({
|
|
1361
1322
|
pubsub: {
|
|
@@ -1363,22 +1324,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1363
1324
|
var _message$id, _message$order_id, _message$type;
|
|
1364
1325
|
console.log('orderDataSource', res);
|
|
1365
1326
|
var pubsubReceivedAt = Date.now();
|
|
1366
|
-
var message =
|
|
1327
|
+
var message = _this11.normalizeOrderSyncMessage(res);
|
|
1367
1328
|
if (!message) return;
|
|
1368
1329
|
message._pubsubReceivedAt = pubsubReceivedAt;
|
|
1369
|
-
|
|
1370
|
-
var throttleMs =
|
|
1371
|
-
var routeInfo =
|
|
1372
|
-
|
|
1330
|
+
_this11.pendingSyncMessages.push(message);
|
|
1331
|
+
var throttleMs = _this11.getOrderSyncThrottleMs();
|
|
1332
|
+
var routeInfo = _this11.resolveSyncMessageRoute(message);
|
|
1333
|
+
_this11.logInfo('orderSync-收到消息并入队', {
|
|
1373
1334
|
id: (_message$id = message.id) !== null && _message$id !== void 0 ? _message$id : null,
|
|
1374
1335
|
order_id: (_message$order_id = message.order_id) !== null && _message$order_id !== void 0 ? _message$order_id : null,
|
|
1375
1336
|
type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : null,
|
|
1376
|
-
pendingCount:
|
|
1337
|
+
pendingCount: _this11.pendingSyncMessages.length,
|
|
1377
1338
|
throttleMs: throttleMs,
|
|
1378
1339
|
pubsubReceivedAt: new Date(pubsubReceivedAt).toISOString(),
|
|
1379
1340
|
fullMessage: JSON.stringify(message)
|
|
1380
1341
|
});
|
|
1381
|
-
|
|
1342
|
+
_this11.scheduleOrderSyncThrottle();
|
|
1382
1343
|
}
|
|
1383
1344
|
}
|
|
1384
1345
|
}).catch(function () {
|
|
@@ -1395,7 +1356,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1395
1356
|
}, {
|
|
1396
1357
|
key: "scheduleOrderSyncThrottle",
|
|
1397
1358
|
value: function scheduleOrderSyncThrottle() {
|
|
1398
|
-
var
|
|
1359
|
+
var _this12 = this;
|
|
1399
1360
|
if (this.isProcessingSyncBatch) return;
|
|
1400
1361
|
if (this.isIdlePhase) {
|
|
1401
1362
|
this.isIdlePhase = false;
|
|
@@ -1406,8 +1367,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1406
1367
|
if (this.syncTimer) return;
|
|
1407
1368
|
var throttleMs = this.getOrderSyncThrottleMs();
|
|
1408
1369
|
this.syncTimer = setTimeout(function () {
|
|
1409
|
-
|
|
1410
|
-
void
|
|
1370
|
+
_this12.syncTimer = undefined;
|
|
1371
|
+
void _this12.flushOrderSyncMessagesByThrottle();
|
|
1411
1372
|
}, throttleMs);
|
|
1412
1373
|
}
|
|
1413
1374
|
|
|
@@ -1475,7 +1436,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1475
1436
|
key: "processOrderSyncMessages",
|
|
1476
1437
|
value: (function () {
|
|
1477
1438
|
var _processOrderSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
1478
|
-
var
|
|
1439
|
+
var _this13 = this;
|
|
1479
1440
|
var messages, batchProcessStartAt, earliestReceivedAt, upsertOrders, refreshIds, uniqueRefreshIds, upsertList, _this$filterRedundant, toFetch, skipped, freshOrders, batchProcessEndAt;
|
|
1480
1441
|
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1481
1442
|
while (1) switch (_context14.prev = _context14.next) {
|
|
@@ -1502,13 +1463,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1502
1463
|
upsertOrders = new Map();
|
|
1503
1464
|
refreshIds = [];
|
|
1504
1465
|
messages.forEach(function (msg, msgIndex) {
|
|
1505
|
-
var routeInfo =
|
|
1466
|
+
var routeInfo = _this13.resolveSyncMessageRoute(msg);
|
|
1506
1467
|
var hasBatchIds = routeInfo.hasBatchIds;
|
|
1507
1468
|
var singleId = routeInfo.singleId;
|
|
1508
1469
|
var hasSingleId = routeInfo.hasSingleId;
|
|
1509
|
-
var normalizedBody =
|
|
1470
|
+
var normalizedBody = _this13.normalizeOrderSyncPayload(msg.body || msg.data);
|
|
1510
1471
|
if (routeInfo.route === 'bodyUpsert' && normalizedBody) {
|
|
1511
|
-
upsertOrders.set(
|
|
1472
|
+
upsertOrders.set(_this13.getIdKey(normalizedBody.order_id), normalizedBody);
|
|
1512
1473
|
return;
|
|
1513
1474
|
}
|
|
1514
1475
|
if (hasBatchIds) refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));else if (routeInfo.route === 'httpRefresh.singleId' && singleId !== null) refreshIds.push(singleId);else if (routeInfo.route === 'httpRefresh.relationIds') refreshIds.push.apply(refreshIds, _toConsumableArray(routeInfo.batchIds));
|
|
@@ -1646,94 +1607,120 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1646
1607
|
key: "mergeOrdersToStore",
|
|
1647
1608
|
value: (function () {
|
|
1648
1609
|
var _mergeOrdersToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(freshOrders, source) {
|
|
1649
|
-
var normalizedFreshOrders,
|
|
1610
|
+
var storeOrderCountBefore, normalizedFreshOrders, _iterator9, _step9, order, id, uniqueFreshOrders, uniqueFreshCount, patchedOrders, mergeActions, updatedList, identityKeyToIndex, index, identityKeys, _iterator10, _step10, key, _iterator11, _step11, fresh, freshIdentityKeys, matchIndex, storageKey, mergeKey, mergedOrder, insertIndex, insertCount, updateCount;
|
|
1650
1611
|
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
1651
1612
|
while (1) switch (_context16.prev = _context16.next) {
|
|
1652
1613
|
case 0:
|
|
1614
|
+
storeOrderCountBefore = this.store.list.length;
|
|
1653
1615
|
this.logInfo('mergeOrdersToStore-开始', {
|
|
1654
1616
|
freshOrderCount: freshOrders.length,
|
|
1655
|
-
storeOrderCountBefore:
|
|
1617
|
+
storeOrderCountBefore: storeOrderCountBefore,
|
|
1656
1618
|
source: source
|
|
1657
1619
|
});
|
|
1658
1620
|
this.logDuplicateOrders("".concat(source, ".beforeMerge"), this.store.list);
|
|
1659
1621
|
normalizedFreshOrders = [];
|
|
1660
|
-
|
|
1661
|
-
_context16.prev =
|
|
1662
|
-
|
|
1663
|
-
case
|
|
1664
|
-
if ((
|
|
1665
|
-
_context16.next =
|
|
1622
|
+
_iterator9 = _createForOfIteratorHelper(freshOrders);
|
|
1623
|
+
_context16.prev = 5;
|
|
1624
|
+
_iterator9.s();
|
|
1625
|
+
case 7:
|
|
1626
|
+
if ((_step9 = _iterator9.n()).done) {
|
|
1627
|
+
_context16.next = 15;
|
|
1666
1628
|
break;
|
|
1667
1629
|
}
|
|
1668
|
-
order =
|
|
1630
|
+
order = _step9.value;
|
|
1669
1631
|
id = order === null || order === void 0 ? void 0 : order.order_id;
|
|
1670
1632
|
if (!(id === undefined || id === null)) {
|
|
1671
|
-
_context16.next =
|
|
1633
|
+
_context16.next = 12;
|
|
1672
1634
|
break;
|
|
1673
1635
|
}
|
|
1674
|
-
return _context16.abrupt("continue",
|
|
1675
|
-
case 11:
|
|
1676
|
-
normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
|
|
1636
|
+
return _context16.abrupt("continue", 13);
|
|
1677
1637
|
case 12:
|
|
1678
|
-
|
|
1638
|
+
normalizedFreshOrders.push(this.normalizeRemoteSyncedOrder(order));
|
|
1639
|
+
case 13:
|
|
1640
|
+
_context16.next = 7;
|
|
1679
1641
|
break;
|
|
1680
|
-
case
|
|
1681
|
-
_context16.next =
|
|
1642
|
+
case 15:
|
|
1643
|
+
_context16.next = 20;
|
|
1682
1644
|
break;
|
|
1683
|
-
case
|
|
1684
|
-
_context16.prev =
|
|
1685
|
-
_context16.t0 = _context16["catch"](
|
|
1686
|
-
|
|
1687
|
-
case
|
|
1688
|
-
_context16.prev =
|
|
1689
|
-
|
|
1690
|
-
return _context16.finish(
|
|
1691
|
-
case
|
|
1645
|
+
case 17:
|
|
1646
|
+
_context16.prev = 17;
|
|
1647
|
+
_context16.t0 = _context16["catch"](5);
|
|
1648
|
+
_iterator9.e(_context16.t0);
|
|
1649
|
+
case 20:
|
|
1650
|
+
_context16.prev = 20;
|
|
1651
|
+
_iterator9.f();
|
|
1652
|
+
return _context16.finish(20);
|
|
1653
|
+
case 23:
|
|
1654
|
+
// 先对本批新单做去重(批内规模 m 很小),保证每条 fresh 身份唯一
|
|
1692
1655
|
uniqueFreshOrders = this.compactOrderListByIdentity(normalizedFreshOrders, "".concat(source, ".incoming")).list;
|
|
1693
1656
|
uniqueFreshCount = uniqueFreshOrders.length;
|
|
1694
1657
|
patchedOrders = [];
|
|
1695
1658
|
mergeActions = {};
|
|
1696
|
-
updatedList = _toConsumableArray(this.store.list);
|
|
1659
|
+
updatedList = _toConsumableArray(this.store.list); // 基于身份键(field:value)建立索引,把「查找已存在订单」从 O(n) 线性扫描降为 O(1),
|
|
1660
|
+
// 整体合并复杂度由 O(n^2) 降为 O(n + m)。索引语义与 doOrdersShareIdentity 完全一致:
|
|
1661
|
+
// 任一身份字段(order_id/external_sale_number/order_number/shop_order_number)同值即同一单。
|
|
1662
|
+
identityKeyToIndex = new Map();
|
|
1663
|
+
for (index = 0; index < updatedList.length; index += 1) {
|
|
1664
|
+
identityKeys = this.getOrderIdentityMatchKeys(updatedList[index]);
|
|
1665
|
+
_iterator10 = _createForOfIteratorHelper(identityKeys);
|
|
1666
|
+
try {
|
|
1667
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
1668
|
+
key = _step10.value;
|
|
1669
|
+
// 同一 key 命中多张时保留最靠前的下标,与原 findIndex「取首个匹配」一致
|
|
1670
|
+
if (!identityKeyToIndex.has(key)) identityKeyToIndex.set(key, index);
|
|
1671
|
+
}
|
|
1672
|
+
} catch (err) {
|
|
1673
|
+
_iterator10.e(err);
|
|
1674
|
+
} finally {
|
|
1675
|
+
_iterator10.f();
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1697
1678
|
_iterator11 = _createForOfIteratorHelper(uniqueFreshOrders);
|
|
1698
|
-
_context16.prev =
|
|
1679
|
+
_context16.prev = 31;
|
|
1699
1680
|
_iterator11.s();
|
|
1700
|
-
case
|
|
1681
|
+
case 33:
|
|
1701
1682
|
if ((_step11 = _iterator11.n()).done) {
|
|
1702
|
-
_context16.next =
|
|
1683
|
+
_context16.next = 53;
|
|
1703
1684
|
break;
|
|
1704
1685
|
}
|
|
1705
1686
|
fresh = _step11.value;
|
|
1706
|
-
|
|
1687
|
+
freshIdentityKeys = this.getOrderIdentityMatchKeys(fresh);
|
|
1688
|
+
matchIndex = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, freshIdentityKeys);
|
|
1707
1689
|
storageKey = this.getOrderStorageKey(fresh);
|
|
1708
1690
|
mergeKey = storageKey || (fresh.order_id !== undefined && fresh.order_id !== null ? this.getIdKey(fresh.order_id) : '');
|
|
1709
1691
|
if (!(matchIndex >= 0)) {
|
|
1710
|
-
_context16.next =
|
|
1692
|
+
_context16.next = 46;
|
|
1711
1693
|
break;
|
|
1712
1694
|
}
|
|
1713
1695
|
mergedOrder = this.mergeOrderRecords(updatedList[matchIndex], fresh);
|
|
1714
1696
|
updatedList[matchIndex] = mergedOrder;
|
|
1697
|
+
// 合并后身份字段可能新增(如挂单拿到 order_id),同步登记到索引,
|
|
1698
|
+
// 供同批后续 fresh 命中同一槽位,避免重复插入
|
|
1699
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex);
|
|
1715
1700
|
patchedOrders.push(mergedOrder);
|
|
1716
1701
|
if (mergeKey) mergeActions[mergeKey] = 'update';
|
|
1717
|
-
return _context16.abrupt("continue",
|
|
1718
|
-
case
|
|
1702
|
+
return _context16.abrupt("continue", 51);
|
|
1703
|
+
case 46:
|
|
1704
|
+
insertIndex = updatedList.length;
|
|
1719
1705
|
updatedList.push(fresh);
|
|
1706
|
+
this.registerOrderIdentityKeys(identityKeyToIndex, fresh, insertIndex);
|
|
1720
1707
|
patchedOrders.push(fresh);
|
|
1721
1708
|
if (mergeKey) mergeActions[mergeKey] = 'insert';
|
|
1722
|
-
case
|
|
1723
|
-
_context16.next =
|
|
1709
|
+
case 51:
|
|
1710
|
+
_context16.next = 33;
|
|
1724
1711
|
break;
|
|
1725
|
-
case
|
|
1726
|
-
_context16.next =
|
|
1712
|
+
case 53:
|
|
1713
|
+
_context16.next = 58;
|
|
1727
1714
|
break;
|
|
1728
|
-
case
|
|
1729
|
-
_context16.prev =
|
|
1730
|
-
_context16.t1 = _context16["catch"](
|
|
1715
|
+
case 55:
|
|
1716
|
+
_context16.prev = 55;
|
|
1717
|
+
_context16.t1 = _context16["catch"](31);
|
|
1731
1718
|
_iterator11.e(_context16.t1);
|
|
1732
|
-
case
|
|
1733
|
-
_context16.prev =
|
|
1719
|
+
case 58:
|
|
1720
|
+
_context16.prev = 58;
|
|
1734
1721
|
_iterator11.f();
|
|
1735
|
-
return _context16.finish(
|
|
1736
|
-
case
|
|
1722
|
+
return _context16.finish(58);
|
|
1723
|
+
case 61:
|
|
1737
1724
|
insertCount = Object.values(mergeActions).filter(function (v) {
|
|
1738
1725
|
return v === 'insert';
|
|
1739
1726
|
}).length;
|
|
@@ -1745,30 +1732,105 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1745
1732
|
updateCount: updateCount,
|
|
1746
1733
|
storeOrderCountAfter: this.store.list.length
|
|
1747
1734
|
});
|
|
1748
|
-
|
|
1735
|
+
// 增量索引已保证 store 去重不变量,无需再对全表做 O(n^2) 压缩;
|
|
1736
|
+
// 仅在自检开关开启时做一次兜底校验。
|
|
1737
|
+
this.store.list = this.runOrderStoreSelfCheck(updatedList, "".concat(source, ".store"));
|
|
1749
1738
|
this.syncOrdersMap();
|
|
1750
|
-
_context16.next =
|
|
1739
|
+
_context16.next = 68;
|
|
1751
1740
|
return this.patchOrdersInSQLite(patchedOrders, source, mergeActions);
|
|
1752
|
-
case
|
|
1741
|
+
case 68:
|
|
1753
1742
|
this.logInfo('mergeOrdersToStore-结束', {
|
|
1754
1743
|
uniqueFreshCount: uniqueFreshCount,
|
|
1755
1744
|
storeOrderCountAfter: this.store.list.length,
|
|
1756
1745
|
insertCount: insertCount,
|
|
1757
1746
|
updateCount: updateCount
|
|
1758
1747
|
});
|
|
1759
|
-
_context16.next =
|
|
1748
|
+
_context16.next = 71;
|
|
1760
1749
|
return this.emitOrdersChanged(patchedOrders, source);
|
|
1761
|
-
case
|
|
1750
|
+
case 71:
|
|
1762
1751
|
case "end":
|
|
1763
1752
|
return _context16.stop();
|
|
1764
1753
|
}
|
|
1765
|
-
}, _callee16, this, [[
|
|
1754
|
+
}, _callee16, this, [[5, 17, 20, 23], [31, 55, 58, 61]]);
|
|
1766
1755
|
}));
|
|
1767
1756
|
function mergeOrdersToStore(_x9, _x10) {
|
|
1768
1757
|
return _mergeOrdersToStore.apply(this, arguments);
|
|
1769
1758
|
}
|
|
1770
1759
|
return mergeOrdersToStore;
|
|
1771
|
-
}()
|
|
1760
|
+
}()
|
|
1761
|
+
/**
|
|
1762
|
+
* 在身份索引中查找与目标订单共享任一身份键的已存在订单下标。
|
|
1763
|
+
* 返回所有命中键里最小的下标,等价于原 findOrderIndexByIdentity 的「取首个匹配」语义。
|
|
1764
|
+
*
|
|
1765
|
+
* @example
|
|
1766
|
+
* const idx = this.lookupOrderIndexByIdentityKeys(identityKeyToIndex, freshIdentityKeys)
|
|
1767
|
+
*/
|
|
1768
|
+
)
|
|
1769
|
+
}, {
|
|
1770
|
+
key: "lookupOrderIndexByIdentityKeys",
|
|
1771
|
+
value: function lookupOrderIndexByIdentityKeys(identityKeyToIndex, identityKeys) {
|
|
1772
|
+
var matchIndex = -1;
|
|
1773
|
+
var _iterator12 = _createForOfIteratorHelper(identityKeys),
|
|
1774
|
+
_step12;
|
|
1775
|
+
try {
|
|
1776
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
1777
|
+
var key = _step12.value;
|
|
1778
|
+
var index = identityKeyToIndex.get(key);
|
|
1779
|
+
if (index === undefined) continue;
|
|
1780
|
+
if (matchIndex < 0 || index < matchIndex) matchIndex = index;
|
|
1781
|
+
}
|
|
1782
|
+
} catch (err) {
|
|
1783
|
+
_iterator12.e(err);
|
|
1784
|
+
} finally {
|
|
1785
|
+
_iterator12.f();
|
|
1786
|
+
}
|
|
1787
|
+
return matchIndex;
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
/**
|
|
1791
|
+
* 将订单的全部身份键登记到索引并指向其在列表中的下标。
|
|
1792
|
+
* 合并后订单新增的身份字段(如挂单同步后拿到 order_id)也会被登记。
|
|
1793
|
+
*
|
|
1794
|
+
* @example
|
|
1795
|
+
* this.registerOrderIdentityKeys(identityKeyToIndex, mergedOrder, matchIndex)
|
|
1796
|
+
*/
|
|
1797
|
+
}, {
|
|
1798
|
+
key: "registerOrderIdentityKeys",
|
|
1799
|
+
value: function registerOrderIdentityKeys(identityKeyToIndex, order, index) {
|
|
1800
|
+
var identityKeys = this.getOrderIdentityMatchKeys(order);
|
|
1801
|
+
var _iterator13 = _createForOfIteratorHelper(identityKeys),
|
|
1802
|
+
_step13;
|
|
1803
|
+
try {
|
|
1804
|
+
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
1805
|
+
var key = _step13.value;
|
|
1806
|
+
identityKeyToIndex.set(key, index);
|
|
1807
|
+
}
|
|
1808
|
+
} catch (err) {
|
|
1809
|
+
_iterator13.e(err);
|
|
1810
|
+
} finally {
|
|
1811
|
+
_iterator13.f();
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
/**
|
|
1816
|
+
* 合并热路径去重兜底:默认直接返回原列表(增量索引已保证无重复)。
|
|
1817
|
+
* 仅当 ORDER_MERGE_SELF_CHECK 开启时,额外做一次全表压缩并在发现残留重复时告警。
|
|
1818
|
+
*/
|
|
1819
|
+
}, {
|
|
1820
|
+
key: "runOrderStoreSelfCheck",
|
|
1821
|
+
value: function runOrderStoreSelfCheck(orders, source) {
|
|
1822
|
+
if (!ORDER_MERGE_SELF_CHECK) return orders;
|
|
1823
|
+
var _this$compactOrderLis = this.compactOrderListByIdentity(orders, source),
|
|
1824
|
+
list = _this$compactOrderLis.list,
|
|
1825
|
+
removedCount = _this$compactOrderLis.removedCount;
|
|
1826
|
+
if (removedCount > 0) {
|
|
1827
|
+
this.logWarning('合并自检发现残留重复订单,已压缩', {
|
|
1828
|
+
source: source,
|
|
1829
|
+
removedCount: removedCount
|
|
1830
|
+
});
|
|
1831
|
+
}
|
|
1832
|
+
return list;
|
|
1833
|
+
}
|
|
1772
1834
|
}, {
|
|
1773
1835
|
key: "normalizeOrderSyncMessage",
|
|
1774
1836
|
value: function normalizeOrderSyncMessage(res) {
|
|
@@ -1801,17 +1863,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1801
1863
|
key: "uniqueOrderIds",
|
|
1802
1864
|
value: function uniqueOrderIds(ids) {
|
|
1803
1865
|
var idMap = new Map();
|
|
1804
|
-
var
|
|
1805
|
-
|
|
1866
|
+
var _iterator14 = _createForOfIteratorHelper(ids),
|
|
1867
|
+
_step14;
|
|
1806
1868
|
try {
|
|
1807
|
-
for (
|
|
1808
|
-
var id =
|
|
1869
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
1870
|
+
var id = _step14.value;
|
|
1809
1871
|
idMap.set(this.getIdKey(id), id);
|
|
1810
1872
|
}
|
|
1811
1873
|
} catch (err) {
|
|
1812
|
-
|
|
1874
|
+
_iterator14.e(err);
|
|
1813
1875
|
} finally {
|
|
1814
|
-
|
|
1876
|
+
_iterator14.f();
|
|
1815
1877
|
}
|
|
1816
1878
|
return _toConsumableArray(idMap.values());
|
|
1817
1879
|
}
|
|
@@ -1823,12 +1885,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1823
1885
|
}, {
|
|
1824
1886
|
key: "isOrderLookupMatch",
|
|
1825
1887
|
value: function isOrderLookupMatch(order, lookupKey) {
|
|
1826
|
-
var
|
|
1888
|
+
var _this14 = this;
|
|
1827
1889
|
if (!order || !lookupKey) return false;
|
|
1828
1890
|
var candidates = [order.order_id, order.external_sale_number, order.order_number, order.shop_order_number, order.shop_full_order_number];
|
|
1829
1891
|
return candidates.some(function (value) {
|
|
1830
1892
|
if (value === undefined || value === null || value === '') return false;
|
|
1831
|
-
return
|
|
1893
|
+
return _this14.getIdKey(value) === lookupKey;
|
|
1832
1894
|
});
|
|
1833
1895
|
}
|
|
1834
1896
|
|
|
@@ -1871,10 +1933,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1871
1933
|
}, {
|
|
1872
1934
|
key: "findOrderIndexByIdentity",
|
|
1873
1935
|
value: function findOrderIndexByIdentity(orders, target) {
|
|
1874
|
-
var
|
|
1936
|
+
var _this15 = this;
|
|
1875
1937
|
if (this.getOrderIdentityMatchKeys(target).length === 0) return -1;
|
|
1876
1938
|
return orders.findIndex(function (order) {
|
|
1877
|
-
return
|
|
1939
|
+
return _this15.doOrdersShareIdentity(order, target);
|
|
1878
1940
|
});
|
|
1879
1941
|
}
|
|
1880
1942
|
}, {
|
|
@@ -1923,58 +1985,58 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1923
1985
|
if (secondaryList.length === 0) return preferredList;
|
|
1924
1986
|
if (preferredList.length === 0) return secondaryList;
|
|
1925
1987
|
var seenKeys = new Set();
|
|
1926
|
-
var
|
|
1927
|
-
|
|
1988
|
+
var _iterator15 = _createForOfIteratorHelper(preferredList),
|
|
1989
|
+
_step15;
|
|
1928
1990
|
try {
|
|
1929
|
-
for (
|
|
1930
|
-
var item =
|
|
1991
|
+
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
1992
|
+
var item = _step15.value;
|
|
1931
1993
|
var keys = this.getProductIdentityKeys(item);
|
|
1932
|
-
var
|
|
1933
|
-
|
|
1994
|
+
var _iterator17 = _createForOfIteratorHelper(keys),
|
|
1995
|
+
_step17;
|
|
1934
1996
|
try {
|
|
1935
|
-
for (
|
|
1936
|
-
var key =
|
|
1997
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
1998
|
+
var key = _step17.value;
|
|
1937
1999
|
seenKeys.add(key);
|
|
1938
2000
|
}
|
|
1939
2001
|
} catch (err) {
|
|
1940
|
-
|
|
2002
|
+
_iterator17.e(err);
|
|
1941
2003
|
} finally {
|
|
1942
|
-
|
|
2004
|
+
_iterator17.f();
|
|
1943
2005
|
}
|
|
1944
2006
|
}
|
|
1945
2007
|
} catch (err) {
|
|
1946
|
-
|
|
2008
|
+
_iterator15.e(err);
|
|
1947
2009
|
} finally {
|
|
1948
|
-
|
|
2010
|
+
_iterator15.f();
|
|
1949
2011
|
}
|
|
1950
2012
|
var result = _toConsumableArray(preferredList);
|
|
1951
|
-
var
|
|
1952
|
-
|
|
2013
|
+
var _iterator16 = _createForOfIteratorHelper(secondaryList),
|
|
2014
|
+
_step16;
|
|
1953
2015
|
try {
|
|
1954
|
-
for (
|
|
1955
|
-
var _item =
|
|
2016
|
+
for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
|
|
2017
|
+
var _item = _step16.value;
|
|
1956
2018
|
var _keys = this.getProductIdentityKeys(_item);
|
|
1957
2019
|
if (_keys.length === 0 || _keys.some(function (key) {
|
|
1958
2020
|
return seenKeys.has(key);
|
|
1959
2021
|
})) continue;
|
|
1960
|
-
var
|
|
1961
|
-
|
|
2022
|
+
var _iterator18 = _createForOfIteratorHelper(_keys),
|
|
2023
|
+
_step18;
|
|
1962
2024
|
try {
|
|
1963
|
-
for (
|
|
1964
|
-
var _key =
|
|
2025
|
+
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
2026
|
+
var _key = _step18.value;
|
|
1965
2027
|
seenKeys.add(_key);
|
|
1966
2028
|
}
|
|
1967
2029
|
} catch (err) {
|
|
1968
|
-
|
|
2030
|
+
_iterator18.e(err);
|
|
1969
2031
|
} finally {
|
|
1970
|
-
|
|
2032
|
+
_iterator18.f();
|
|
1971
2033
|
}
|
|
1972
2034
|
result.push(cloneDeep(_item));
|
|
1973
2035
|
}
|
|
1974
2036
|
} catch (err) {
|
|
1975
|
-
|
|
2037
|
+
_iterator16.e(err);
|
|
1976
2038
|
} finally {
|
|
1977
|
-
|
|
2039
|
+
_iterator16.f();
|
|
1978
2040
|
}
|
|
1979
2041
|
return result;
|
|
1980
2042
|
}
|
|
@@ -2000,29 +2062,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2000
2062
|
}, {
|
|
2001
2063
|
key: "mergeOrderPaymentLists",
|
|
2002
2064
|
value: function mergeOrderPaymentLists(existing, incoming) {
|
|
2003
|
-
var
|
|
2065
|
+
var _this16 = this;
|
|
2004
2066
|
var existingList = Array.isArray(existing) ? existing : [];
|
|
2005
2067
|
var incomingList = Array.isArray(incoming) ? incoming : [];
|
|
2006
2068
|
if (incomingList.length === 0) return cloneDeep(existingList);
|
|
2007
2069
|
if (existingList.length === 0) return cloneDeep(incomingList);
|
|
2008
2070
|
var existingByKey = new Map();
|
|
2009
|
-
var
|
|
2010
|
-
|
|
2071
|
+
var _iterator19 = _createForOfIteratorHelper(existingList),
|
|
2072
|
+
_step19;
|
|
2011
2073
|
try {
|
|
2012
|
-
for (
|
|
2013
|
-
var payment =
|
|
2074
|
+
for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
|
|
2075
|
+
var payment = _step19.value;
|
|
2014
2076
|
var key = this.getPaymentMergeKey(payment);
|
|
2015
2077
|
if (!key) continue;
|
|
2016
2078
|
existingByKey.set(key, payment);
|
|
2017
2079
|
}
|
|
2018
2080
|
} catch (err) {
|
|
2019
|
-
|
|
2081
|
+
_iterator19.e(err);
|
|
2020
2082
|
} finally {
|
|
2021
|
-
|
|
2083
|
+
_iterator19.f();
|
|
2022
2084
|
}
|
|
2023
2085
|
return incomingList.map(function (payment) {
|
|
2024
2086
|
var incomingPayment = payment;
|
|
2025
|
-
var key =
|
|
2087
|
+
var key = _this16.getPaymentMergeKey(incomingPayment);
|
|
2026
2088
|
var existingPayment = key ? existingByKey.get(key) : undefined;
|
|
2027
2089
|
if (!existingPayment) return cloneDeep(incomingPayment);
|
|
2028
2090
|
return _objectSpread(_objectSpread(_objectSpread({}, cloneDeep(existingPayment)), cloneDeep(incomingPayment)), {}, {
|
|
@@ -2079,30 +2141,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2079
2141
|
key: "summarizeDuplicateOrders",
|
|
2080
2142
|
value: function summarizeDuplicateOrders(orders) {
|
|
2081
2143
|
var groups = new Map();
|
|
2082
|
-
var
|
|
2083
|
-
|
|
2144
|
+
var _iterator20 = _createForOfIteratorHelper(orders),
|
|
2145
|
+
_step20;
|
|
2084
2146
|
try {
|
|
2085
|
-
for (
|
|
2086
|
-
var order =
|
|
2087
|
-
var
|
|
2088
|
-
|
|
2147
|
+
for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
|
|
2148
|
+
var order = _step20.value;
|
|
2149
|
+
var _iterator21 = _createForOfIteratorHelper(this.getOrderIdentityMatchKeys(order)),
|
|
2150
|
+
_step21;
|
|
2089
2151
|
try {
|
|
2090
|
-
for (
|
|
2091
|
-
var key =
|
|
2152
|
+
for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
|
|
2153
|
+
var key = _step21.value;
|
|
2092
2154
|
var group = groups.get(key) || [];
|
|
2093
2155
|
group.push(order);
|
|
2094
2156
|
groups.set(key, group);
|
|
2095
2157
|
}
|
|
2096
2158
|
} catch (err) {
|
|
2097
|
-
|
|
2159
|
+
_iterator21.e(err);
|
|
2098
2160
|
} finally {
|
|
2099
|
-
|
|
2161
|
+
_iterator21.f();
|
|
2100
2162
|
}
|
|
2101
2163
|
}
|
|
2102
2164
|
} catch (err) {
|
|
2103
|
-
|
|
2165
|
+
_iterator20.e(err);
|
|
2104
2166
|
} finally {
|
|
2105
|
-
|
|
2167
|
+
_iterator20.f();
|
|
2106
2168
|
}
|
|
2107
2169
|
return _toConsumableArray(groups.entries()).filter(function (_ref2) {
|
|
2108
2170
|
var _ref3 = _slicedToArray(_ref2, 2),
|
|
@@ -2144,11 +2206,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2144
2206
|
value: function compactOrderListByIdentity(orders, source) {
|
|
2145
2207
|
var list = [];
|
|
2146
2208
|
var removedCount = 0;
|
|
2147
|
-
var
|
|
2148
|
-
|
|
2209
|
+
var _iterator22 = _createForOfIteratorHelper(orders),
|
|
2210
|
+
_step22;
|
|
2149
2211
|
try {
|
|
2150
|
-
for (
|
|
2151
|
-
var order =
|
|
2212
|
+
for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
|
|
2213
|
+
var order = _step22.value;
|
|
2152
2214
|
var matchIndex = this.findOrderIndexByIdentity(list, order);
|
|
2153
2215
|
if (matchIndex < 0) {
|
|
2154
2216
|
list.push(order);
|
|
@@ -2158,9 +2220,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2158
2220
|
removedCount += 1;
|
|
2159
2221
|
}
|
|
2160
2222
|
} catch (err) {
|
|
2161
|
-
|
|
2223
|
+
_iterator22.e(err);
|
|
2162
2224
|
} finally {
|
|
2163
|
-
|
|
2225
|
+
_iterator22.f();
|
|
2164
2226
|
}
|
|
2165
2227
|
if (removedCount > 0) {
|
|
2166
2228
|
this.logWarning('订单列表重复项已压缩', {
|
|
@@ -2306,15 +2368,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2306
2368
|
}, {
|
|
2307
2369
|
key: "mergeRemoteSnapshotWithPendingOrders",
|
|
2308
2370
|
value: function mergeRemoteSnapshotWithPendingOrders(remoteOrders, existingOrders) {
|
|
2309
|
-
var
|
|
2371
|
+
var _this17 = this;
|
|
2310
2372
|
var merged = remoteOrders.map(function (order) {
|
|
2311
|
-
return
|
|
2373
|
+
return _this17.normalizeRemoteSyncedOrder(order);
|
|
2312
2374
|
});
|
|
2313
|
-
var
|
|
2314
|
-
|
|
2375
|
+
var _iterator23 = _createForOfIteratorHelper(existingOrders),
|
|
2376
|
+
_step23;
|
|
2315
2377
|
try {
|
|
2316
|
-
for (
|
|
2317
|
-
var order =
|
|
2378
|
+
for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
|
|
2379
|
+
var order = _step23.value;
|
|
2318
2380
|
if (!this.isPendingSyncOrder(order)) continue;
|
|
2319
2381
|
var matchIndex = this.findOrderIndexByIdentity(merged, order);
|
|
2320
2382
|
if (matchIndex >= 0) {
|
|
@@ -2325,9 +2387,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2325
2387
|
merged.push(order);
|
|
2326
2388
|
}
|
|
2327
2389
|
} catch (err) {
|
|
2328
|
-
|
|
2390
|
+
_iterator23.e(err);
|
|
2329
2391
|
} finally {
|
|
2330
|
-
|
|
2392
|
+
_iterator23.f();
|
|
2331
2393
|
}
|
|
2332
2394
|
return this.compactOrderListByIdentity(merged, 'mergeRemoteSnapshotWithPendingOrders').list;
|
|
2333
2395
|
}
|
|
@@ -2377,7 +2439,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2377
2439
|
key: "patchOrdersInSQLite",
|
|
2378
2440
|
value: (function () {
|
|
2379
2441
|
var _patchOrdersInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(orders, source) {
|
|
2380
|
-
var
|
|
2442
|
+
var _this18 = this;
|
|
2381
2443
|
var mergeActions,
|
|
2382
2444
|
ordersSnapshot,
|
|
2383
2445
|
_this$filterRedundant2,
|
|
@@ -2396,7 +2458,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2396
2458
|
return _context20.abrupt("return");
|
|
2397
2459
|
case 3:
|
|
2398
2460
|
ordersSnapshot = cloneDeep(orders).filter(function (order) {
|
|
2399
|
-
return
|
|
2461
|
+
return _this18.getOrderStorageKey(order);
|
|
2400
2462
|
});
|
|
2401
2463
|
if (!(ordersSnapshot.length === 0)) {
|
|
2402
2464
|
_context20.next = 6;
|
|
@@ -2421,54 +2483,54 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2421
2483
|
_context20.prev = 12;
|
|
2422
2484
|
_context20.next = 15;
|
|
2423
2485
|
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
|
|
2424
|
-
var writeMethod,
|
|
2486
|
+
var writeMethod, _iterator24, _step24, order;
|
|
2425
2487
|
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
2426
2488
|
while (1) switch (_context19.prev = _context19.next) {
|
|
2427
2489
|
case 0:
|
|
2428
2490
|
writeMethod = 'none';
|
|
2429
|
-
|
|
2491
|
+
_this18.logInfo('patchOrdersInSQLite-开始', {
|
|
2430
2492
|
source: source,
|
|
2431
2493
|
count: compactedToWrite.length,
|
|
2432
2494
|
dedupedCount: skipped.length
|
|
2433
2495
|
});
|
|
2434
|
-
if (!(typeof
|
|
2496
|
+
if (!(typeof _this18.dbManager.bulkUpdate === 'function')) {
|
|
2435
2497
|
_context19.next = 8;
|
|
2436
2498
|
break;
|
|
2437
2499
|
}
|
|
2438
2500
|
writeMethod = 'bulkUpdate';
|
|
2439
2501
|
_context19.next = 6;
|
|
2440
|
-
return
|
|
2502
|
+
return _this18.dbManager.bulkUpdate(INDEXDB_STORE_NAME, compactedToWrite);
|
|
2441
2503
|
case 6:
|
|
2442
2504
|
_context19.next = 33;
|
|
2443
2505
|
break;
|
|
2444
2506
|
case 8:
|
|
2445
|
-
if (!(typeof
|
|
2507
|
+
if (!(typeof _this18.dbManager.bulkAdd === 'function')) {
|
|
2446
2508
|
_context19.next = 14;
|
|
2447
2509
|
break;
|
|
2448
2510
|
}
|
|
2449
2511
|
writeMethod = 'bulkAdd';
|
|
2450
2512
|
_context19.next = 12;
|
|
2451
|
-
return
|
|
2513
|
+
return _this18.dbManager.bulkAdd(INDEXDB_STORE_NAME, compactedToWrite);
|
|
2452
2514
|
case 12:
|
|
2453
2515
|
_context19.next = 33;
|
|
2454
2516
|
break;
|
|
2455
2517
|
case 14:
|
|
2456
|
-
if (!(typeof
|
|
2518
|
+
if (!(typeof _this18.dbManager.update === 'function')) {
|
|
2457
2519
|
_context19.next = 33;
|
|
2458
2520
|
break;
|
|
2459
2521
|
}
|
|
2460
2522
|
writeMethod = 'update';
|
|
2461
|
-
|
|
2523
|
+
_iterator24 = _createForOfIteratorHelper(compactedToWrite);
|
|
2462
2524
|
_context19.prev = 17;
|
|
2463
|
-
|
|
2525
|
+
_iterator24.s();
|
|
2464
2526
|
case 19:
|
|
2465
|
-
if ((
|
|
2527
|
+
if ((_step24 = _iterator24.n()).done) {
|
|
2466
2528
|
_context19.next = 25;
|
|
2467
2529
|
break;
|
|
2468
2530
|
}
|
|
2469
|
-
order =
|
|
2531
|
+
order = _step24.value;
|
|
2470
2532
|
_context19.next = 23;
|
|
2471
|
-
return
|
|
2533
|
+
return _this18.dbManager.update(INDEXDB_STORE_NAME, order);
|
|
2472
2534
|
case 23:
|
|
2473
2535
|
_context19.next = 19;
|
|
2474
2536
|
break;
|
|
@@ -2478,14 +2540,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2478
2540
|
case 27:
|
|
2479
2541
|
_context19.prev = 27;
|
|
2480
2542
|
_context19.t0 = _context19["catch"](17);
|
|
2481
|
-
|
|
2543
|
+
_iterator24.e(_context19.t0);
|
|
2482
2544
|
case 30:
|
|
2483
2545
|
_context19.prev = 30;
|
|
2484
|
-
|
|
2546
|
+
_iterator24.f();
|
|
2485
2547
|
return _context19.finish(30);
|
|
2486
2548
|
case 33:
|
|
2487
|
-
|
|
2488
|
-
|
|
2549
|
+
_this18.recordRecentSqliteWrite(source, compactedToWrite);
|
|
2550
|
+
_this18.logInfo('patchOrdersInSQLite-完成', {
|
|
2489
2551
|
source: source,
|
|
2490
2552
|
count: compactedToWrite.length,
|
|
2491
2553
|
writeMethod: writeMethod,
|
|
@@ -2529,7 +2591,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2529
2591
|
key: "updateOrderInSQLite",
|
|
2530
2592
|
value: (function () {
|
|
2531
2593
|
var _updateOrderInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(order, source) {
|
|
2532
|
-
var
|
|
2594
|
+
var _this19 = this;
|
|
2533
2595
|
var orderSnapshot, _orderSnapshot$order_3;
|
|
2534
2596
|
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
2535
2597
|
while (1) switch (_context22.prev = _context22.next) {
|
|
@@ -2550,43 +2612,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2550
2612
|
while (1) switch (_context21.prev = _context21.next) {
|
|
2551
2613
|
case 0:
|
|
2552
2614
|
writeMethod = 'none';
|
|
2553
|
-
|
|
2615
|
+
_this19.logInfo('updateOrderInSQLite-开始', {
|
|
2554
2616
|
source: source,
|
|
2555
2617
|
orderId: (_orderSnapshot$order_ = orderSnapshot.order_id) !== null && _orderSnapshot$order_ !== void 0 ? _orderSnapshot$order_ : null,
|
|
2556
|
-
storageKey:
|
|
2618
|
+
storageKey: _this19.getOrderStorageKey(orderSnapshot)
|
|
2557
2619
|
});
|
|
2558
|
-
if (!(typeof
|
|
2620
|
+
if (!(typeof _this19.dbManager.update === 'function')) {
|
|
2559
2621
|
_context21.next = 8;
|
|
2560
2622
|
break;
|
|
2561
2623
|
}
|
|
2562
2624
|
writeMethod = 'update';
|
|
2563
2625
|
_context21.next = 6;
|
|
2564
|
-
return
|
|
2626
|
+
return _this19.dbManager.update(INDEXDB_STORE_NAME, orderSnapshot);
|
|
2565
2627
|
case 6:
|
|
2566
2628
|
_context21.next = 18;
|
|
2567
2629
|
break;
|
|
2568
2630
|
case 8:
|
|
2569
|
-
if (!(typeof
|
|
2631
|
+
if (!(typeof _this19.dbManager.bulkUpdate === 'function')) {
|
|
2570
2632
|
_context21.next = 14;
|
|
2571
2633
|
break;
|
|
2572
2634
|
}
|
|
2573
2635
|
writeMethod = 'bulkUpdate';
|
|
2574
2636
|
_context21.next = 12;
|
|
2575
|
-
return
|
|
2637
|
+
return _this19.dbManager.bulkUpdate(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
2576
2638
|
case 12:
|
|
2577
2639
|
_context21.next = 18;
|
|
2578
2640
|
break;
|
|
2579
2641
|
case 14:
|
|
2580
|
-
if (!(typeof
|
|
2642
|
+
if (!(typeof _this19.dbManager.bulkAdd === 'function')) {
|
|
2581
2643
|
_context21.next = 18;
|
|
2582
2644
|
break;
|
|
2583
2645
|
}
|
|
2584
2646
|
writeMethod = 'bulkAdd';
|
|
2585
2647
|
_context21.next = 18;
|
|
2586
|
-
return
|
|
2648
|
+
return _this19.dbManager.bulkAdd(INDEXDB_STORE_NAME, [orderSnapshot]);
|
|
2587
2649
|
case 18:
|
|
2588
|
-
|
|
2589
|
-
|
|
2650
|
+
_this19.recordRecentSqliteWrite(source, [orderSnapshot]);
|
|
2651
|
+
_this19.logInfo('updateOrderInSQLite-完成', {
|
|
2590
2652
|
source: source,
|
|
2591
2653
|
orderId: (_orderSnapshot$order_2 = orderSnapshot.order_id) !== null && _orderSnapshot$order_2 !== void 0 ? _orderSnapshot$order_2 : null,
|
|
2592
2654
|
writeMethod: writeMethod
|
|
@@ -2629,7 +2691,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2629
2691
|
key: "replaceOrdersSnapshotInSQLite",
|
|
2630
2692
|
value: (function () {
|
|
2631
2693
|
var _replaceOrdersSnapshotInSQLite = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(orderList, source) {
|
|
2632
|
-
var
|
|
2694
|
+
var _this20 = this;
|
|
2633
2695
|
var remoteSnapshot, mergedSnapshot;
|
|
2634
2696
|
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
2635
2697
|
while (1) switch (_context24.prev = _context24.next) {
|
|
@@ -2639,12 +2701,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2639
2701
|
break;
|
|
2640
2702
|
}
|
|
2641
2703
|
return _context24.abrupt("return", this.compactOrderListByIdentity(orderList.map(function (order) {
|
|
2642
|
-
return
|
|
2704
|
+
return _this20.normalizeRemoteSyncedOrder(order);
|
|
2643
2705
|
}), "".concat(source, ".snapshotNoDb")).list);
|
|
2644
2706
|
case 2:
|
|
2645
2707
|
remoteSnapshot = cloneDeep(orderList);
|
|
2646
2708
|
mergedSnapshot = this.compactOrderListByIdentity(remoteSnapshot.map(function (order) {
|
|
2647
|
-
return
|
|
2709
|
+
return _this20.normalizeRemoteSyncedOrder(order);
|
|
2648
2710
|
}), "".concat(source, ".remoteSnapshot")).list;
|
|
2649
2711
|
_context24.prev = 4;
|
|
2650
2712
|
_context24.next = 7;
|
|
@@ -2653,12 +2715,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2653
2715
|
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
2654
2716
|
while (1) switch (_context23.prev = _context23.next) {
|
|
2655
2717
|
case 0:
|
|
2656
|
-
if (!(typeof
|
|
2718
|
+
if (!(typeof _this20.dbManager.getAll === 'function')) {
|
|
2657
2719
|
_context23.next = 6;
|
|
2658
2720
|
break;
|
|
2659
2721
|
}
|
|
2660
2722
|
_context23.next = 3;
|
|
2661
|
-
return
|
|
2723
|
+
return _this20.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
2662
2724
|
case 3:
|
|
2663
2725
|
_context23.t0 = _context23.sent;
|
|
2664
2726
|
_context23.next = 7;
|
|
@@ -2667,18 +2729,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2667
2729
|
_context23.t0 = [];
|
|
2668
2730
|
case 7:
|
|
2669
2731
|
existingOrders = _context23.t0;
|
|
2670
|
-
orderListSnapshot =
|
|
2671
|
-
mergedSnapshot =
|
|
2672
|
-
|
|
2732
|
+
orderListSnapshot = _this20.mergeRemoteSnapshotWithPendingOrders(remoteSnapshot, existingOrders || []);
|
|
2733
|
+
mergedSnapshot = _this20.compactOrderListByIdentity(orderListSnapshot, "".concat(source, ".sqliteSnapshot")).list;
|
|
2734
|
+
_this20.logInfo('replaceOrdersSnapshotInSQLite-开始', {
|
|
2673
2735
|
source: source,
|
|
2674
2736
|
count: mergedSnapshot.length,
|
|
2675
2737
|
remoteCount: remoteSnapshot.length,
|
|
2676
2738
|
preservedPendingCount: mergedSnapshot.length - remoteSnapshot.length
|
|
2677
2739
|
});
|
|
2678
2740
|
_context23.next = 13;
|
|
2679
|
-
return
|
|
2741
|
+
return _this20.dbManager.clear(INDEXDB_STORE_NAME);
|
|
2680
2742
|
case 13:
|
|
2681
|
-
|
|
2743
|
+
_this20.logInfo('replaceOrdersSnapshotInSQLite-clear完成', {
|
|
2682
2744
|
count: mergedSnapshot.length
|
|
2683
2745
|
});
|
|
2684
2746
|
if (!(mergedSnapshot.length === 0)) {
|
|
@@ -2688,10 +2750,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2688
2750
|
return _context23.abrupt("return");
|
|
2689
2751
|
case 16:
|
|
2690
2752
|
_context23.next = 18;
|
|
2691
|
-
return
|
|
2753
|
+
return _this20.dbManager.bulkAdd(INDEXDB_STORE_NAME, mergedSnapshot);
|
|
2692
2754
|
case 18:
|
|
2693
|
-
|
|
2694
|
-
|
|
2755
|
+
_this20.recordRecentSqliteWrite(source, mergedSnapshot);
|
|
2756
|
+
_this20.logInfo('replaceOrdersSnapshotInSQLite-bulkAdd完成', {
|
|
2695
2757
|
source: source,
|
|
2696
2758
|
count: mergedSnapshot.length
|
|
2697
2759
|
});
|
|
@@ -2735,34 +2797,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2735
2797
|
key: "clear",
|
|
2736
2798
|
value: (function () {
|
|
2737
2799
|
var _clear = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
|
|
2738
|
-
var
|
|
2800
|
+
var _this21 = this;
|
|
2739
2801
|
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
2740
2802
|
while (1) switch (_context26.prev = _context26.next) {
|
|
2741
2803
|
case 0:
|
|
2742
2804
|
this.store.list = [];
|
|
2743
2805
|
this.store.map = new Map();
|
|
2744
|
-
this.resourceIdIndex.clear();
|
|
2745
2806
|
if (!this.dbManager) {
|
|
2746
|
-
_context26.next =
|
|
2807
|
+
_context26.next = 5;
|
|
2747
2808
|
break;
|
|
2748
2809
|
}
|
|
2749
|
-
_context26.next =
|
|
2810
|
+
_context26.next = 5;
|
|
2750
2811
|
return this.runInOrderSQLiteSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
2751
2812
|
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
2752
2813
|
while (1) switch (_context25.prev = _context25.next) {
|
|
2753
2814
|
case 0:
|
|
2754
2815
|
_context25.next = 2;
|
|
2755
|
-
return
|
|
2816
|
+
return _this21.dbManager.clear(INDEXDB_STORE_NAME);
|
|
2756
2817
|
case 2:
|
|
2757
2818
|
case "end":
|
|
2758
2819
|
return _context25.stop();
|
|
2759
2820
|
}
|
|
2760
2821
|
}, _callee25);
|
|
2761
2822
|
})));
|
|
2762
|
-
case
|
|
2823
|
+
case 5:
|
|
2763
2824
|
this.setStorageItem(ORDER_LAST_FULL_FETCH_AT_STORAGE_KEY, '');
|
|
2764
2825
|
this.emitOrdersChanged([], 'clear');
|
|
2765
|
-
case
|
|
2826
|
+
case 7:
|
|
2766
2827
|
case "end":
|
|
2767
2828
|
return _context26.stop();
|
|
2768
2829
|
}
|