@pisell/pisellos 2.2.191 → 2.2.192
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/server/modules/order/index.d.ts +1 -68
- package/dist/server/modules/order/index.js +334 -761
- package/dist/server/modules/products/index.d.ts +0 -57
- package/dist/server/modules/products/index.js +347 -706
- package/lib/server/modules/order/index.d.ts +1 -68
- package/lib/server/modules/order/index.js +6 -376
- package/lib/server/modules/products/index.d.ts +0 -57
- package/lib/server/modules/products/index.js +0 -333
- package/package.json +1 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
5
2
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
6
3
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
4
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
5
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
9
6
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
7
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
8
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
14
9
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
13
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
15
15
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
16
16
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
17
17
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
@@ -37,16 +37,6 @@ import { applyDetailValueToProducts, applyPriceDataToProducts, applyI18nToProduc
|
|
|
37
37
|
* IndexDB 存储名称
|
|
38
38
|
*/
|
|
39
39
|
var INDEXDB_STORE_NAME = 'products';
|
|
40
|
-
/** window 上挂载的商品流程调试日志 key */
|
|
41
|
-
var PRODUCT_FLOW_LOG_WINDOW_KEY = '__productModuleFlowLogs';
|
|
42
|
-
/** window 上按商品 id 聚合的 IndexDB 写入统计 key */
|
|
43
|
-
var PRODUCT_WRITE_STATS_WINDOW_KEY = '__productModuleWriteStats';
|
|
44
|
-
var PRODUCT_FLOW_LOG_MAX_LENGTH = 1000;
|
|
45
|
-
|
|
46
|
-
/** 商品模块流程调试日志条目 */
|
|
47
|
-
|
|
48
|
-
/** 单个商品 IndexDB 写入记录 */
|
|
49
|
-
|
|
50
40
|
/** 商品同步防抖时间(毫秒) */
|
|
51
41
|
var PRODUCT_SYNC_DEBOUNCE_MS = 10000;
|
|
52
42
|
/** silentRefresh 最小间隔,避免 preload 后立即全量重拉 */
|
|
@@ -91,8 +81,6 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
91
81
|
_defineProperty(_assertThisInitialized(_this), "productDataSource", void 0);
|
|
92
82
|
_defineProperty(_assertThisInitialized(_this), "pendingSyncMessages", []);
|
|
93
83
|
_defineProperty(_assertThisInitialized(_this), "syncTimer", void 0);
|
|
94
|
-
/** IndexDB 写入序号,便于日志关联 */
|
|
95
|
-
_defineProperty(_assertThisInitialized(_this), "productFlowWriteSeq", 0);
|
|
96
84
|
/** 最近一次 SSE 全量拉取完成时间 */
|
|
97
85
|
_defineProperty(_assertThisInitialized(_this), "lastServerFullFetchAtMs", 0);
|
|
98
86
|
/** 最近一次 preload 完成时间(含 IndexDB 命中) */
|
|
@@ -145,18 +133,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
145
133
|
|
|
146
134
|
// 初始化商品数据同步(pubsub 订阅)
|
|
147
135
|
this.setupProductSync();
|
|
148
|
-
this.initProductFlowLogs();
|
|
149
|
-
this.pushProductFlowLog('initialize.complete', {
|
|
150
|
-
hasDbManager: !!this.dbManager,
|
|
151
|
-
hasLogger: !!this.logger,
|
|
152
|
-
initialProductCount: this.store.list.length
|
|
153
|
-
});
|
|
154
136
|
this.logInfo('模块初始化完成', {
|
|
155
137
|
hasDbManager: !!this.dbManager,
|
|
156
138
|
hasLogger: !!this.logger,
|
|
157
139
|
initialProductCount: this.store.list.length
|
|
158
140
|
});
|
|
159
|
-
case
|
|
141
|
+
case 11:
|
|
160
142
|
case "end":
|
|
161
143
|
return _context.stop();
|
|
162
144
|
}
|
|
@@ -228,163 +210,6 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
228
210
|
} catch (_unused3) {
|
|
229
211
|
// 日志记录失败不影响主流程
|
|
230
212
|
}
|
|
231
|
-
this.pushProductFlowLog("error.".concat(title), metadata);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* 初始化 window 上的商品流程调试日志。
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* window.clearProductModuleFlowLogs()
|
|
239
|
-
* copy(window.exportProductModuleFlowLogs?.() || '[]')
|
|
240
|
-
*/
|
|
241
|
-
}, {
|
|
242
|
-
key: "initProductFlowLogs",
|
|
243
|
-
value: function initProductFlowLogs() {
|
|
244
|
-
var _this2 = this;
|
|
245
|
-
try {
|
|
246
|
-
var win = typeof globalThis !== 'undefined' ? globalThis.window : undefined;
|
|
247
|
-
if (!win) return;
|
|
248
|
-
win[PRODUCT_FLOW_LOG_WINDOW_KEY] = [];
|
|
249
|
-
win[PRODUCT_WRITE_STATS_WINDOW_KEY] = {};
|
|
250
|
-
win.clearProductModuleFlowLogs = function () {
|
|
251
|
-
win[PRODUCT_FLOW_LOG_WINDOW_KEY] = [];
|
|
252
|
-
win[PRODUCT_WRITE_STATS_WINDOW_KEY] = {};
|
|
253
|
-
_this2.productFlowWriteSeq = 0;
|
|
254
|
-
_this2.pushProductFlowLog('debug.clear', {});
|
|
255
|
-
};
|
|
256
|
-
win.exportProductModuleFlowLogs = function () {
|
|
257
|
-
var logs = win[PRODUCT_FLOW_LOG_WINDOW_KEY] || [];
|
|
258
|
-
return JSON.stringify(logs, null, 2);
|
|
259
|
-
};
|
|
260
|
-
win.exportProductModuleWriteStats = function () {
|
|
261
|
-
var stats = win[PRODUCT_WRITE_STATS_WINDOW_KEY] || {};
|
|
262
|
-
return JSON.stringify(stats, null, 2);
|
|
263
|
-
};
|
|
264
|
-
win.summarizeProductModuleWrites = function () {
|
|
265
|
-
var topN = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 20;
|
|
266
|
-
var stats = win[PRODUCT_WRITE_STATS_WINDOW_KEY] || {};
|
|
267
|
-
return Object.entries(stats).map(function (_ref) {
|
|
268
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
269
|
-
productId = _ref2[0],
|
|
270
|
-
entries = _ref2[1];
|
|
271
|
-
var list = entries || [];
|
|
272
|
-
var sources = _toConsumableArray(new Set(list.map(function (item) {
|
|
273
|
-
return item.source;
|
|
274
|
-
})));
|
|
275
|
-
var last = list[list.length - 1];
|
|
276
|
-
return {
|
|
277
|
-
productId: Number(productId),
|
|
278
|
-
writeCount: list.length,
|
|
279
|
-
sources: sources,
|
|
280
|
-
lastWriteAt: (last === null || last === void 0 ? void 0 : last.ts) || ''
|
|
281
|
-
};
|
|
282
|
-
}).sort(function (a, b) {
|
|
283
|
-
return b.writeCount - a.writeCount;
|
|
284
|
-
}).slice(0, topN);
|
|
285
|
-
};
|
|
286
|
-
this.pushProductFlowLog('debug.init', {
|
|
287
|
-
logKey: PRODUCT_FLOW_LOG_WINDOW_KEY,
|
|
288
|
-
writeStatsKey: PRODUCT_WRITE_STATS_WINDOW_KEY,
|
|
289
|
-
indexDbStrategy: '全量 replaceProductsSnapshotInIndexDB + 增量 patchProductsInIndexDB',
|
|
290
|
-
helpers: ['clearProductModuleFlowLogs', 'exportProductModuleFlowLogs', 'exportProductModuleWriteStats', 'summarizeProductModuleWrites']
|
|
291
|
-
});
|
|
292
|
-
} catch (_unused4) {
|
|
293
|
-
// window 不可用时忽略
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* 写入 window 商品流程调试日志。
|
|
299
|
-
*
|
|
300
|
-
* @example
|
|
301
|
-
* this.pushProductFlowLog('mergeProductsToStore.start', { count: 3 })
|
|
302
|
-
*/
|
|
303
|
-
}, {
|
|
304
|
-
key: "pushProductFlowLog",
|
|
305
|
-
value: function pushProductFlowLog(step, metadata) {
|
|
306
|
-
try {
|
|
307
|
-
var win = typeof globalThis !== 'undefined' ? globalThis.window : undefined;
|
|
308
|
-
if (!win) return;
|
|
309
|
-
if (!Array.isArray(win[PRODUCT_FLOW_LOG_WINDOW_KEY])) {
|
|
310
|
-
win[PRODUCT_FLOW_LOG_WINDOW_KEY] = [];
|
|
311
|
-
}
|
|
312
|
-
var entry = {
|
|
313
|
-
ts: new Date().toISOString(),
|
|
314
|
-
step: step,
|
|
315
|
-
metadata: metadata || {}
|
|
316
|
-
};
|
|
317
|
-
win[PRODUCT_FLOW_LOG_WINDOW_KEY].push(entry);
|
|
318
|
-
var logs = win[PRODUCT_FLOW_LOG_WINDOW_KEY];
|
|
319
|
-
if (logs.length > PRODUCT_FLOW_LOG_MAX_LENGTH) {
|
|
320
|
-
logs.splice(0, logs.length - PRODUCT_FLOW_LOG_MAX_LENGTH);
|
|
321
|
-
}
|
|
322
|
-
console.log("[ProductFlow] ".concat(step), metadata || {});
|
|
323
|
-
} catch (_unused5) {
|
|
324
|
-
// 调试日志失败不影响主流程
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/** 当前内存 store 快照,供流程日志使用 */
|
|
329
|
-
}, {
|
|
330
|
-
key: "getProductStoreSnapshot",
|
|
331
|
-
value: function getProductStoreSnapshot() {
|
|
332
|
-
return {
|
|
333
|
-
storeListCount: this.store.list.length,
|
|
334
|
-
storeMapCount: this.store.map.size,
|
|
335
|
-
pendingSyncCount: this.pendingSyncMessages.length
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* 记录 IndexDB 写入统计(按 productId 聚合)。
|
|
341
|
-
*
|
|
342
|
-
* @example
|
|
343
|
-
* this.trackProductWrite('pubsub.mergeProductsToStore', 'clear+bulkUpdate', products, { 1: 'update' })
|
|
344
|
-
*/
|
|
345
|
-
}, {
|
|
346
|
-
key: "trackProductWrite",
|
|
347
|
-
value: function trackProductWrite(source, writeMethod, products) {
|
|
348
|
-
var mergeActions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
349
|
-
var defaultMergeAction = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'update';
|
|
350
|
-
this.productFlowWriteSeq += 1;
|
|
351
|
-
var writeSeq = this.productFlowWriteSeq;
|
|
352
|
-
try {
|
|
353
|
-
var win = typeof globalThis !== 'undefined' ? globalThis.window : undefined;
|
|
354
|
-
if (!win) return writeSeq;
|
|
355
|
-
if (!win[PRODUCT_WRITE_STATS_WINDOW_KEY]) {
|
|
356
|
-
win[PRODUCT_WRITE_STATS_WINDOW_KEY] = {};
|
|
357
|
-
}
|
|
358
|
-
var stats = win[PRODUCT_WRITE_STATS_WINDOW_KEY];
|
|
359
|
-
var _iterator = _createForOfIteratorHelper(products),
|
|
360
|
-
_step;
|
|
361
|
-
try {
|
|
362
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
363
|
-
var product = _step.value;
|
|
364
|
-
var productId = product === null || product === void 0 ? void 0 : product.id;
|
|
365
|
-
if (productId === undefined || productId === null) continue;
|
|
366
|
-
var mergeAction = mergeActions[productId] || defaultMergeAction;
|
|
367
|
-
var entry = {
|
|
368
|
-
ts: new Date().toISOString(),
|
|
369
|
-
writeSeq: writeSeq,
|
|
370
|
-
source: source,
|
|
371
|
-
writeMethod: writeMethod,
|
|
372
|
-
productId: productId,
|
|
373
|
-
mergeAction: mergeAction
|
|
374
|
-
};
|
|
375
|
-
var key = String(productId);
|
|
376
|
-
if (!stats[key]) stats[key] = [];
|
|
377
|
-
stats[key].push(entry);
|
|
378
|
-
}
|
|
379
|
-
} catch (err) {
|
|
380
|
-
_iterator.e(err);
|
|
381
|
-
} finally {
|
|
382
|
-
_iterator.f();
|
|
383
|
-
}
|
|
384
|
-
} catch (_unused6) {
|
|
385
|
-
// 统计失败不影响主流程
|
|
386
|
-
}
|
|
387
|
-
return writeSeq;
|
|
388
213
|
}
|
|
389
214
|
|
|
390
215
|
/**
|
|
@@ -394,13 +219,13 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
394
219
|
}, {
|
|
395
220
|
key: "loadProductsPrice",
|
|
396
221
|
value: (function () {
|
|
397
|
-
var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(
|
|
398
|
-
var
|
|
399
|
-
var
|
|
222
|
+
var _loadProductsPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
|
|
223
|
+
var _this2 = this;
|
|
224
|
+
var _ref$ids, ids, schedule_date, schedule_datetime, customer_id, startTime, datetime, idSet, products, priceData, duration, _duration, errorMessage;
|
|
400
225
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
401
226
|
while (1) switch (_context2.prev = _context2.next) {
|
|
402
227
|
case 0:
|
|
403
|
-
|
|
228
|
+
_ref$ids = _ref.ids, ids = _ref$ids === void 0 ? [] : _ref$ids, schedule_date = _ref.schedule_date, schedule_datetime = _ref.schedule_datetime, customer_id = _ref.customer_id;
|
|
404
229
|
this.logInfo('开始加载商品价格', {
|
|
405
230
|
productCount: ids.length,
|
|
406
231
|
schedule_date: schedule_date,
|
|
@@ -418,7 +243,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
418
243
|
return idSet.has(product.id);
|
|
419
244
|
});
|
|
420
245
|
priceData = products.map(function (product) {
|
|
421
|
-
return
|
|
246
|
+
return _this2.buildPriceDataFromQuotation(product, datetime, customer_id);
|
|
422
247
|
});
|
|
423
248
|
duration = Date.now() - startTime;
|
|
424
249
|
this.logInfo('加载商品价格成功', {
|
|
@@ -492,17 +317,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
492
317
|
if (!hasLoadedScheduleList) {
|
|
493
318
|
var _params$scheduleModul, _params$scheduleModul2;
|
|
494
319
|
var scheduleList = ((_params$scheduleModul = (_params$scheduleModul2 = params.scheduleModule).getScheduleList) === null || _params$scheduleModul === void 0 ? void 0 : _params$scheduleModul.call(_params$scheduleModul2)) || [];
|
|
495
|
-
var
|
|
496
|
-
|
|
320
|
+
var _iterator = _createForOfIteratorHelper(scheduleList),
|
|
321
|
+
_step;
|
|
497
322
|
try {
|
|
498
|
-
for (
|
|
499
|
-
var schedule =
|
|
323
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
324
|
+
var schedule = _step.value;
|
|
500
325
|
scheduleCache.set(String(schedule.id), schedule);
|
|
501
326
|
}
|
|
502
327
|
} catch (err) {
|
|
503
|
-
|
|
328
|
+
_iterator.e(err);
|
|
504
329
|
} finally {
|
|
505
|
-
|
|
330
|
+
_iterator.f();
|
|
506
331
|
}
|
|
507
332
|
hasLoadedScheduleList = true;
|
|
508
333
|
}
|
|
@@ -535,7 +360,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
535
360
|
key: "refreshQuotationPriceBridge",
|
|
536
361
|
value: (function () {
|
|
537
362
|
var _refreshQuotationPriceBridge = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
|
|
538
|
-
var
|
|
363
|
+
var _this3 = this;
|
|
539
364
|
var refreshKey;
|
|
540
365
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
541
366
|
while (1) switch (_context4.prev = _context4.next) {
|
|
@@ -567,10 +392,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
567
392
|
this.quotationBridgeRefreshPromise = this.quotationPriceBridge.loadQuotations({
|
|
568
393
|
channel: this.quotationBridgeChannel
|
|
569
394
|
}).then(function () {
|
|
570
|
-
|
|
395
|
+
_this3.quotationBridgeLoadedKey = refreshKey;
|
|
571
396
|
}).finally(function () {
|
|
572
|
-
|
|
573
|
-
|
|
397
|
+
_this3.quotationBridgeRefreshPromise = undefined;
|
|
398
|
+
_this3.quotationBridgeRefreshKey = undefined;
|
|
574
399
|
});
|
|
575
400
|
_context4.next = 14;
|
|
576
401
|
return this.quotationBridgeRefreshPromise;
|
|
@@ -639,14 +464,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
639
464
|
}, {
|
|
640
465
|
key: "buildPriceDataFromQuotation",
|
|
641
466
|
value: function buildPriceDataFromQuotation(product, datetime, customerId) {
|
|
642
|
-
var _this$quotationPriceB,
|
|
467
|
+
var _this$quotationPriceB, _ref2, _ref3;
|
|
643
468
|
var quotedPrice = (_this$quotationPriceB = this.quotationPriceBridge) === null || _this$quotationPriceB === void 0 ? void 0 : _this$quotationPriceB.getPriceForProduct({
|
|
644
469
|
productId: product.id,
|
|
645
470
|
datetime: datetime,
|
|
646
471
|
customer_id: customerId
|
|
647
472
|
});
|
|
648
473
|
var productPrice = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : product.price;
|
|
649
|
-
var productBasePrice = (
|
|
474
|
+
var productBasePrice = (_ref2 = (_ref3 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : product.base_price) !== null && _ref3 !== void 0 ? _ref3 : product.price) !== null && _ref2 !== void 0 ? _ref2 : 0;
|
|
650
475
|
return {
|
|
651
476
|
id: product.id,
|
|
652
477
|
price: String(productPrice !== null && productPrice !== void 0 ? productPrice : 0),
|
|
@@ -658,18 +483,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
658
483
|
}, {
|
|
659
484
|
key: "buildVariantPriceData",
|
|
660
485
|
value: function buildVariantPriceData(product, datetime, customerId) {
|
|
661
|
-
var
|
|
486
|
+
var _this4 = this;
|
|
662
487
|
if (!Array.isArray(product.variant)) return [];
|
|
663
488
|
return product.variant.map(function (variant) {
|
|
664
|
-
var
|
|
665
|
-
var quotedPrice = (
|
|
489
|
+
var _this4$quotationPrice, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _variant$product_id;
|
|
490
|
+
var quotedPrice = (_this4$quotationPrice = _this4.quotationPriceBridge) === null || _this4$quotationPrice === void 0 ? void 0 : _this4$quotationPrice.getPriceForProduct({
|
|
666
491
|
productId: product.id,
|
|
667
492
|
variantId: Number(variant.id),
|
|
668
493
|
datetime: datetime,
|
|
669
494
|
customer_id: customerId
|
|
670
495
|
});
|
|
671
|
-
var price = (
|
|
672
|
-
var basePrice = (
|
|
496
|
+
var price = (_ref4 = (_ref5 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : variant.price) !== null && _ref5 !== void 0 ? _ref5 : product.price) !== null && _ref4 !== void 0 ? _ref4 : 0;
|
|
497
|
+
var basePrice = (_ref6 = (_ref7 = (_ref8 = (_ref9 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : variant.base_price) !== null && _ref9 !== void 0 ? _ref9 : variant.price) !== null && _ref8 !== void 0 ? _ref8 : product.base_price) !== null && _ref7 !== void 0 ? _ref7 : product.price) !== null && _ref6 !== void 0 ? _ref6 : 0;
|
|
673
498
|
return {
|
|
674
499
|
id: Number(variant.id),
|
|
675
500
|
product_id: Number((_variant$product_id = variant.product_id) !== null && _variant$product_id !== void 0 ? _variant$product_id : product.id),
|
|
@@ -681,23 +506,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
681
506
|
}, {
|
|
682
507
|
key: "buildBundleGroupPriceData",
|
|
683
508
|
value: function buildBundleGroupPriceData(product, datetime, customerId) {
|
|
684
|
-
var
|
|
509
|
+
var _this5 = this;
|
|
685
510
|
if (!Array.isArray(product.bundle_group)) return [];
|
|
686
511
|
return product.bundle_group.map(function (group) {
|
|
687
512
|
return {
|
|
688
513
|
id: Number(group.id),
|
|
689
514
|
bundle_item: (group.bundle_item || []).map(function (item) {
|
|
690
|
-
var
|
|
515
|
+
var _this5$quotationPrice, _ref10, _ref11, _ref12, _item$product_id, _item$group_id;
|
|
691
516
|
var bundleProductId = Number(item.bundle_product_id);
|
|
692
517
|
var bundleVariantId = Number(item.bundle_variant_id || 0);
|
|
693
|
-
var quotedPrice = (
|
|
518
|
+
var quotedPrice = (_this5$quotationPrice = _this5.quotationPriceBridge) === null || _this5$quotationPrice === void 0 ? void 0 : _this5$quotationPrice.getPriceForProduct({
|
|
694
519
|
productId: bundleProductId,
|
|
695
520
|
variantId: bundleVariantId,
|
|
696
521
|
datetime: datetime,
|
|
697
522
|
customer_id: customerId
|
|
698
523
|
});
|
|
699
|
-
var price = (
|
|
700
|
-
var basePrice = (
|
|
524
|
+
var price = (_ref10 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.price) !== null && _ref10 !== void 0 ? _ref10 : 0;
|
|
525
|
+
var basePrice = (_ref11 = (_ref12 = quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : item.base_price) !== null && _ref12 !== void 0 ? _ref12 : item.price) !== null && _ref11 !== void 0 ? _ref11 : 0;
|
|
701
526
|
return {
|
|
702
527
|
id: Number(item.id),
|
|
703
528
|
product_id: Number((_item$product_id = item.product_id) !== null && _item$product_id !== void 0 ? _item$product_id : product.id),
|
|
@@ -730,7 +555,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
730
555
|
value: (function () {
|
|
731
556
|
var _getProductsWithPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(schedule_date, extraContext, options) {
|
|
732
557
|
var _options$changedIds;
|
|
733
|
-
var t0, scopedProductIds, cacheKey, scopedProductIdSet, changedIds, cachedProducts, updatedProducts, updatedMap, mergedCache,
|
|
558
|
+
var t0, scopedProductIds, cacheKey, scopedProductIdSet, changedIds, cachedProducts, updatedProducts, updatedMap, mergedCache, _iterator2, _step2, p, _iterator3, _step3, _p, errorMessage, result;
|
|
734
559
|
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
735
560
|
while (1) switch (_context6.prev = _context6.next) {
|
|
736
561
|
case 0:
|
|
@@ -771,10 +596,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
771
596
|
return [p.id, p];
|
|
772
597
|
}));
|
|
773
598
|
mergedCache = [];
|
|
774
|
-
|
|
599
|
+
_iterator2 = _createForOfIteratorHelper(cachedProducts);
|
|
775
600
|
try {
|
|
776
|
-
for (
|
|
777
|
-
p =
|
|
601
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
602
|
+
p = _step2.value;
|
|
778
603
|
if (updatedMap.has(p.id)) {
|
|
779
604
|
mergedCache.push(updatedMap.get(p.id));
|
|
780
605
|
updatedMap.delete(p.id);
|
|
@@ -784,20 +609,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
784
609
|
}
|
|
785
610
|
// 剩余的是新增商品(create 场景)
|
|
786
611
|
} catch (err) {
|
|
787
|
-
|
|
612
|
+
_iterator2.e(err);
|
|
788
613
|
} finally {
|
|
789
|
-
|
|
614
|
+
_iterator2.f();
|
|
790
615
|
}
|
|
791
|
-
|
|
616
|
+
_iterator3 = _createForOfIteratorHelper(updatedMap.values());
|
|
792
617
|
try {
|
|
793
|
-
for (
|
|
794
|
-
_p =
|
|
618
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
619
|
+
_p = _step3.value;
|
|
795
620
|
mergedCache.push(_p);
|
|
796
621
|
}
|
|
797
622
|
} catch (err) {
|
|
798
|
-
|
|
623
|
+
_iterator3.e(err);
|
|
799
624
|
} finally {
|
|
800
|
-
|
|
625
|
+
_iterator3.f();
|
|
801
626
|
}
|
|
802
627
|
this.productsPriceCache.set(cacheKey, mergedCache);
|
|
803
628
|
this.logInfo('增量更新完成', {
|
|
@@ -1032,25 +857,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1032
857
|
}
|
|
1033
858
|
if (productIds.length === 0 && collectionIds.length === 0) return [];
|
|
1034
859
|
var result = new Set();
|
|
1035
|
-
var
|
|
1036
|
-
|
|
860
|
+
var _iterator4 = _createForOfIteratorHelper(productIds),
|
|
861
|
+
_step4;
|
|
1037
862
|
try {
|
|
1038
|
-
for (
|
|
1039
|
-
var id =
|
|
863
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
864
|
+
var id = _step4.value;
|
|
1040
865
|
if (this.store.map.has(id)) result.add(id);
|
|
1041
866
|
}
|
|
1042
867
|
} catch (err) {
|
|
1043
|
-
|
|
868
|
+
_iterator4.e(err);
|
|
1044
869
|
} finally {
|
|
1045
|
-
|
|
870
|
+
_iterator4.f();
|
|
1046
871
|
}
|
|
1047
872
|
if (collectionIds.length === 0) return Array.from(result);
|
|
1048
873
|
var collectionIdSet = new Set(collectionIds);
|
|
1049
|
-
var
|
|
1050
|
-
|
|
874
|
+
var _iterator5 = _createForOfIteratorHelper(this.getProductsRef()),
|
|
875
|
+
_step5;
|
|
1051
876
|
try {
|
|
1052
|
-
for (
|
|
1053
|
-
var product =
|
|
877
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
878
|
+
var product = _step5.value;
|
|
1054
879
|
if (result.has(product.id)) continue;
|
|
1055
880
|
if (!Array.isArray(product.collection)) continue;
|
|
1056
881
|
var isInCollection = product.collection.some(function (collection) {
|
|
@@ -1059,9 +884,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1059
884
|
if (isInCollection) result.add(product.id);
|
|
1060
885
|
}
|
|
1061
886
|
} catch (err) {
|
|
1062
|
-
|
|
887
|
+
_iterator5.e(err);
|
|
1063
888
|
} finally {
|
|
1064
|
-
|
|
889
|
+
_iterator5.f();
|
|
1065
890
|
}
|
|
1066
891
|
return Array.from(result);
|
|
1067
892
|
}
|
|
@@ -1280,48 +1105,38 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1280
1105
|
this.logWarning('loadProductsByServer: ProductDataSource 不可用');
|
|
1281
1106
|
return _context9.abrupt("return", []);
|
|
1282
1107
|
case 3:
|
|
1283
|
-
this.pushProductFlowLog('loadProductsByServer.start', this.getProductStoreSnapshot());
|
|
1284
1108
|
this.logInfo('开始通过 DataSource SSE 加载商品列表');
|
|
1285
1109
|
t0 = performance.now();
|
|
1286
|
-
_context9.prev =
|
|
1110
|
+
_context9.prev = 5;
|
|
1287
1111
|
tSSE = performance.now();
|
|
1288
|
-
_context9.next =
|
|
1112
|
+
_context9.next = 9;
|
|
1289
1113
|
return this.productDataSource.run({
|
|
1290
1114
|
sse: {}
|
|
1291
1115
|
});
|
|
1292
|
-
case
|
|
1116
|
+
case 9:
|
|
1293
1117
|
productList = _context9.sent;
|
|
1294
1118
|
list = productList || [];
|
|
1295
1119
|
perfMark('loadProductsByServer.SSE', performance.now() - tSSE, {
|
|
1296
1120
|
count: list.length
|
|
1297
1121
|
});
|
|
1298
|
-
this.pushProductFlowLog('loadProductsByServer.sseSuccess', {
|
|
1299
|
-
count: list.length
|
|
1300
|
-
});
|
|
1301
1122
|
this.logInfo('通过 DataSource SSE 加载商品列表成功', {
|
|
1302
1123
|
productCount: list.length,
|
|
1303
1124
|
duration: "".concat(Math.round(performance.now() - t0), "ms")
|
|
1304
1125
|
});
|
|
1305
|
-
_context9.next =
|
|
1126
|
+
_context9.next = 15;
|
|
1306
1127
|
return this.replaceProductsSnapshotInIndexDB(list, 'loadProductsByServer');
|
|
1307
|
-
case
|
|
1128
|
+
case 15:
|
|
1308
1129
|
this.lastServerFullFetchAtMs = Date.now();
|
|
1309
|
-
_context9.next =
|
|
1130
|
+
_context9.next = 18;
|
|
1310
1131
|
return this.core.effects.emit(ProductsHooks.onProductsLoaded, list);
|
|
1311
|
-
case
|
|
1312
|
-
this.pushProductFlowLog('loadProductsByServer.done', _objectSpread({
|
|
1313
|
-
count: list.length
|
|
1314
|
-
}, this.getProductStoreSnapshot()));
|
|
1132
|
+
case 18:
|
|
1315
1133
|
perfMark('loadProductsByServer', performance.now() - t0, {
|
|
1316
1134
|
count: list.length
|
|
1317
1135
|
});
|
|
1318
1136
|
return _context9.abrupt("return", list);
|
|
1319
|
-
case
|
|
1320
|
-
_context9.prev =
|
|
1321
|
-
_context9.t0 = _context9["catch"](
|
|
1322
|
-
this.pushProductFlowLog('loadProductsByServer.failed', {
|
|
1323
|
-
error: _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0)
|
|
1324
|
-
});
|
|
1137
|
+
case 22:
|
|
1138
|
+
_context9.prev = 22;
|
|
1139
|
+
_context9.t0 = _context9["catch"](5);
|
|
1325
1140
|
duration = Math.round(performance.now() - t0);
|
|
1326
1141
|
errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
|
|
1327
1142
|
console.error('[Products] 加载商品数据失败:', _context9.t0);
|
|
@@ -1330,11 +1145,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1330
1145
|
error: errorMessage
|
|
1331
1146
|
});
|
|
1332
1147
|
return _context9.abrupt("return", []);
|
|
1333
|
-
case
|
|
1148
|
+
case 29:
|
|
1334
1149
|
case "end":
|
|
1335
1150
|
return _context9.stop();
|
|
1336
1151
|
}
|
|
1337
|
-
}, _callee9, this, [[
|
|
1152
|
+
}, _callee9, this, [[5, 22]]);
|
|
1338
1153
|
}));
|
|
1339
1154
|
function loadProductsByServer() {
|
|
1340
1155
|
return _loadProductsByServer.apply(this, arguments);
|
|
@@ -1351,11 +1166,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1351
1166
|
key: "fetchProductsByHttp",
|
|
1352
1167
|
value: (function () {
|
|
1353
1168
|
var _fetchProductsByHttp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(params) {
|
|
1354
|
-
var
|
|
1169
|
+
var _ref13, _ref13$category_ids, category_ids, _ref13$product_ids, product_ids, _ref13$collection, collection, customer_id, cacheId, startTime, _this$otherParams3, _productsData$data, productsData, productList, duration, _duration2, errorMessage;
|
|
1355
1170
|
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
1356
1171
|
while (1) switch (_context10.prev = _context10.next) {
|
|
1357
1172
|
case 0:
|
|
1358
|
-
|
|
1173
|
+
_ref13 = params || {}, _ref13$category_ids = _ref13.category_ids, category_ids = _ref13$category_ids === void 0 ? [] : _ref13$category_ids, _ref13$product_ids = _ref13.product_ids, product_ids = _ref13$product_ids === void 0 ? [] : _ref13$product_ids, _ref13$collection = _ref13.collection, collection = _ref13$collection === void 0 ? [] : _ref13$collection, customer_id = _ref13.customer_id, cacheId = _ref13.cacheId;
|
|
1359
1174
|
this.logInfo('fetchProductsByHttp: 开始请求', {
|
|
1360
1175
|
categoryIdsCount: category_ids.length,
|
|
1361
1176
|
productIdsCount: product_ids.length,
|
|
@@ -1430,29 +1245,23 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1430
1245
|
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
1431
1246
|
while (1) switch (_context11.prev = _context11.next) {
|
|
1432
1247
|
case 0:
|
|
1433
|
-
|
|
1434
|
-
params: params || {}
|
|
1435
|
-
}, this.getProductStoreSnapshot()));
|
|
1436
|
-
_context11.next = 3;
|
|
1248
|
+
_context11.next = 2;
|
|
1437
1249
|
return this.fetchProductsByHttp(params);
|
|
1438
|
-
case
|
|
1250
|
+
case 2:
|
|
1439
1251
|
productList = _context11.sent;
|
|
1440
1252
|
if (!(productList.length > 0)) {
|
|
1441
|
-
_context11.next =
|
|
1253
|
+
_context11.next = 9;
|
|
1442
1254
|
break;
|
|
1443
1255
|
}
|
|
1444
|
-
_context11.next =
|
|
1256
|
+
_context11.next = 6;
|
|
1445
1257
|
return this.replaceProductsSnapshotInIndexDB(productList, 'loadProductsByServerHttp');
|
|
1446
|
-
case
|
|
1258
|
+
case 6:
|
|
1447
1259
|
this.lastServerFullFetchAtMs = Date.now();
|
|
1448
|
-
_context11.next =
|
|
1260
|
+
_context11.next = 9;
|
|
1449
1261
|
return this.core.effects.emit(ProductsHooks.onProductsLoaded, productList);
|
|
1450
|
-
case
|
|
1451
|
-
this.pushProductFlowLog('loadProductsByServerHttp.done', _objectSpread({
|
|
1452
|
-
count: productList.length
|
|
1453
|
-
}, this.getProductStoreSnapshot()));
|
|
1262
|
+
case 9:
|
|
1454
1263
|
return _context11.abrupt("return", productList);
|
|
1455
|
-
case
|
|
1264
|
+
case 10:
|
|
1456
1265
|
case "end":
|
|
1457
1266
|
return _context11.stop();
|
|
1458
1267
|
}
|
|
@@ -1510,18 +1319,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1510
1319
|
key: "getProductsRefByIds",
|
|
1511
1320
|
value: function getProductsRefByIds(ids) {
|
|
1512
1321
|
var products = [];
|
|
1513
|
-
var
|
|
1514
|
-
|
|
1322
|
+
var _iterator6 = _createForOfIteratorHelper(ids),
|
|
1323
|
+
_step6;
|
|
1515
1324
|
try {
|
|
1516
|
-
for (
|
|
1517
|
-
var id =
|
|
1325
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
1326
|
+
var id = _step6.value;
|
|
1518
1327
|
var product = this.store.map.get(id);
|
|
1519
1328
|
if (product) products.push(product);
|
|
1520
1329
|
}
|
|
1521
1330
|
} catch (err) {
|
|
1522
|
-
|
|
1331
|
+
_iterator6.e(err);
|
|
1523
1332
|
} finally {
|
|
1524
|
-
|
|
1333
|
+
_iterator6.f();
|
|
1525
1334
|
}
|
|
1526
1335
|
return products;
|
|
1527
1336
|
}
|
|
@@ -1560,16 +1369,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1560
1369
|
key: "removeProductsByIds",
|
|
1561
1370
|
value: (function () {
|
|
1562
1371
|
var _removeProductsByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(ids) {
|
|
1563
|
-
var idSet,
|
|
1372
|
+
var idSet, _iterator7, _step7, _id, _iterator8, _step8, id, errorMessage, _iterator9, _step9, _step9$value, dateKey, cachedProducts;
|
|
1564
1373
|
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
1565
1374
|
while (1) switch (_context14.prev = _context14.next) {
|
|
1566
1375
|
case 0:
|
|
1567
1376
|
idSet = new Set(ids);
|
|
1568
|
-
this.pushProductFlowLog('removeProductsByIds.start', _objectSpread({
|
|
1569
|
-
ids: ids,
|
|
1570
|
-
count: ids.length,
|
|
1571
|
-
writeStrategy: 'delete-by-id'
|
|
1572
|
-
}, this.getProductStoreSnapshot()));
|
|
1573
1377
|
this.logInfo('removeProductsByIds', {
|
|
1574
1378
|
ids: ids,
|
|
1575
1379
|
count: ids.length
|
|
@@ -1577,91 +1381,81 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1577
1381
|
this.store.list = this.store.list.filter(function (p) {
|
|
1578
1382
|
return !idSet.has(p.id);
|
|
1579
1383
|
});
|
|
1580
|
-
|
|
1384
|
+
_iterator7 = _createForOfIteratorHelper(ids);
|
|
1581
1385
|
try {
|
|
1582
|
-
for (
|
|
1583
|
-
_id =
|
|
1386
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
1387
|
+
_id = _step7.value;
|
|
1584
1388
|
this.store.map.delete(_id);
|
|
1585
1389
|
}
|
|
1586
1390
|
} catch (err) {
|
|
1587
|
-
|
|
1391
|
+
_iterator7.e(err);
|
|
1588
1392
|
} finally {
|
|
1589
|
-
|
|
1393
|
+
_iterator7.f();
|
|
1590
1394
|
}
|
|
1591
1395
|
if (!this.dbManager) {
|
|
1592
|
-
_context14.next =
|
|
1396
|
+
_context14.next = 30;
|
|
1593
1397
|
break;
|
|
1594
1398
|
}
|
|
1595
|
-
_context14.prev =
|
|
1596
|
-
|
|
1597
|
-
_context14.prev =
|
|
1598
|
-
|
|
1599
|
-
case
|
|
1600
|
-
if ((
|
|
1601
|
-
_context14.next =
|
|
1399
|
+
_context14.prev = 6;
|
|
1400
|
+
_iterator8 = _createForOfIteratorHelper(ids);
|
|
1401
|
+
_context14.prev = 8;
|
|
1402
|
+
_iterator8.s();
|
|
1403
|
+
case 10:
|
|
1404
|
+
if ((_step8 = _iterator8.n()).done) {
|
|
1405
|
+
_context14.next = 16;
|
|
1602
1406
|
break;
|
|
1603
1407
|
}
|
|
1604
|
-
id =
|
|
1605
|
-
_context14.next =
|
|
1408
|
+
id = _step8.value;
|
|
1409
|
+
_context14.next = 14;
|
|
1606
1410
|
return this.dbManager.delete(INDEXDB_STORE_NAME, id);
|
|
1607
|
-
case
|
|
1608
|
-
_context14.next =
|
|
1411
|
+
case 14:
|
|
1412
|
+
_context14.next = 10;
|
|
1609
1413
|
break;
|
|
1610
|
-
case
|
|
1611
|
-
_context14.next =
|
|
1414
|
+
case 16:
|
|
1415
|
+
_context14.next = 21;
|
|
1612
1416
|
break;
|
|
1613
|
-
case
|
|
1614
|
-
_context14.prev =
|
|
1615
|
-
_context14.t0 = _context14["catch"](
|
|
1616
|
-
|
|
1617
|
-
case
|
|
1618
|
-
_context14.prev =
|
|
1619
|
-
|
|
1620
|
-
return _context14.finish(
|
|
1621
|
-
case
|
|
1622
|
-
|
|
1623
|
-
return {
|
|
1624
|
-
id: id
|
|
1625
|
-
};
|
|
1626
|
-
}), Object.fromEntries(ids.map(function (id) {
|
|
1627
|
-
return [id, 'delete'];
|
|
1628
|
-
})), 'delete');
|
|
1629
|
-
_context14.next = 32;
|
|
1417
|
+
case 18:
|
|
1418
|
+
_context14.prev = 18;
|
|
1419
|
+
_context14.t0 = _context14["catch"](8);
|
|
1420
|
+
_iterator8.e(_context14.t0);
|
|
1421
|
+
case 21:
|
|
1422
|
+
_context14.prev = 21;
|
|
1423
|
+
_iterator8.f();
|
|
1424
|
+
return _context14.finish(21);
|
|
1425
|
+
case 24:
|
|
1426
|
+
_context14.next = 30;
|
|
1630
1427
|
break;
|
|
1631
|
-
case
|
|
1632
|
-
_context14.prev =
|
|
1633
|
-
_context14.t1 = _context14["catch"](
|
|
1428
|
+
case 26:
|
|
1429
|
+
_context14.prev = 26;
|
|
1430
|
+
_context14.t1 = _context14["catch"](6);
|
|
1634
1431
|
errorMessage = _context14.t1 instanceof Error ? _context14.t1.message : String(_context14.t1);
|
|
1635
1432
|
this.logError('removeProductsByIds: IndexDB 删除失败', {
|
|
1636
1433
|
ids: ids,
|
|
1637
1434
|
error: errorMessage
|
|
1638
1435
|
});
|
|
1639
|
-
case
|
|
1640
|
-
|
|
1436
|
+
case 30:
|
|
1437
|
+
_iterator9 = _createForOfIteratorHelper(this.productsPriceCache.entries());
|
|
1641
1438
|
try {
|
|
1642
|
-
for (
|
|
1643
|
-
|
|
1439
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
1440
|
+
_step9$value = _slicedToArray(_step9.value, 2), dateKey = _step9$value[0], cachedProducts = _step9$value[1];
|
|
1644
1441
|
this.productsPriceCache.set(dateKey, cachedProducts.filter(function (p) {
|
|
1645
1442
|
return !idSet.has(p.id);
|
|
1646
1443
|
}));
|
|
1647
1444
|
}
|
|
1648
1445
|
} catch (err) {
|
|
1649
|
-
|
|
1446
|
+
_iterator9.e(err);
|
|
1650
1447
|
} finally {
|
|
1651
|
-
|
|
1448
|
+
_iterator9.f();
|
|
1652
1449
|
}
|
|
1653
1450
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
1654
|
-
this.pushProductFlowLog('removeProductsByIds.done', _objectSpread({
|
|
1655
|
-
ids: ids
|
|
1656
|
-
}, this.getProductStoreSnapshot()));
|
|
1657
1451
|
this.logInfo('removeProductsByIds 完成', {
|
|
1658
1452
|
remaining: this.store.list.length
|
|
1659
1453
|
});
|
|
1660
|
-
case
|
|
1454
|
+
case 34:
|
|
1661
1455
|
case "end":
|
|
1662
1456
|
return _context14.stop();
|
|
1663
1457
|
}
|
|
1664
|
-
}, _callee14, this, [[
|
|
1458
|
+
}, _callee14, this, [[6, 26], [8, 18, 21, 24]]);
|
|
1665
1459
|
}));
|
|
1666
1460
|
function removeProductsByIds(_x18) {
|
|
1667
1461
|
return _removeProductsByIds.apply(this, arguments);
|
|
@@ -1682,11 +1476,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1682
1476
|
while (1) switch (_context15.prev = _context15.next) {
|
|
1683
1477
|
case 0:
|
|
1684
1478
|
tTotal = performance.now();
|
|
1685
|
-
this.pushProductFlowLog('refreshProducts.start', this.getProductStoreSnapshot());
|
|
1686
1479
|
this.logInfo('refreshProducts 开始');
|
|
1687
|
-
_context15.next =
|
|
1480
|
+
_context15.next = 4;
|
|
1688
1481
|
return this.loadProductsByServer();
|
|
1689
|
-
case
|
|
1482
|
+
case 4:
|
|
1690
1483
|
products = _context15.sent;
|
|
1691
1484
|
if (products && products.length > 0) {
|
|
1692
1485
|
// 服务器返回的数据已经是全新的,无需 cloneDeep
|
|
@@ -1702,12 +1495,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1702
1495
|
perfMark('refreshProducts', performance.now() - tTotal, {
|
|
1703
1496
|
count: this.store.list.length
|
|
1704
1497
|
});
|
|
1705
|
-
this.pushProductFlowLog('refreshProducts.done', _objectSpread({
|
|
1706
|
-
count: this.store.list.length,
|
|
1707
|
-
durationMs: Math.round(performance.now() - tTotal)
|
|
1708
|
-
}, this.getProductStoreSnapshot()));
|
|
1709
1498
|
return _context15.abrupt("return", this.store.list);
|
|
1710
|
-
case
|
|
1499
|
+
case 8:
|
|
1711
1500
|
case "end":
|
|
1712
1501
|
return _context15.stop();
|
|
1713
1502
|
}
|
|
@@ -1871,96 +1660,70 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1871
1660
|
key: "replaceProductsSnapshotInIndexDB",
|
|
1872
1661
|
value: (function () {
|
|
1873
1662
|
var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(products, source) {
|
|
1874
|
-
var
|
|
1663
|
+
var _this6 = this;
|
|
1875
1664
|
var errorMessage;
|
|
1876
1665
|
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1877
1666
|
while (1) switch (_context20.prev = _context20.next) {
|
|
1878
1667
|
case 0:
|
|
1879
1668
|
if (this.dbManager) {
|
|
1880
|
-
_context20.next =
|
|
1669
|
+
_context20.next = 3;
|
|
1881
1670
|
break;
|
|
1882
1671
|
}
|
|
1883
|
-
this.pushProductFlowLog('replaceProductsSnapshotInIndexDB.skip', {
|
|
1884
|
-
source: source,
|
|
1885
|
-
reason: 'no_dbManager',
|
|
1886
|
-
inputCount: products.length
|
|
1887
|
-
});
|
|
1888
1672
|
this.logWarning('replaceProductsSnapshotInIndexDB: dbManager 不可用');
|
|
1889
1673
|
return _context20.abrupt("return");
|
|
1890
|
-
case
|
|
1891
|
-
_context20.prev =
|
|
1892
|
-
_context20.next =
|
|
1674
|
+
case 3:
|
|
1675
|
+
_context20.prev = 3;
|
|
1676
|
+
_context20.next = 6;
|
|
1893
1677
|
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
|
|
1894
|
-
var t0
|
|
1678
|
+
var t0;
|
|
1895
1679
|
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1896
1680
|
while (1) switch (_context19.prev = _context19.next) {
|
|
1897
1681
|
case 0:
|
|
1898
|
-
|
|
1899
|
-
source: source,
|
|
1900
|
-
writeStrategy: 'clear+bulkUpdate',
|
|
1901
|
-
inputCount: products.length,
|
|
1902
|
-
storeListCount: _this7.store.list.length
|
|
1903
|
-
});
|
|
1904
|
-
_this7.logInfo('replaceProductsSnapshotInIndexDB 开始', {
|
|
1682
|
+
_this6.logInfo('replaceProductsSnapshotInIndexDB 开始', {
|
|
1905
1683
|
source: source,
|
|
1906
1684
|
productCount: products.length
|
|
1907
1685
|
});
|
|
1908
1686
|
t0 = performance.now();
|
|
1909
|
-
_context19.next =
|
|
1910
|
-
return
|
|
1911
|
-
case
|
|
1912
|
-
_this7.pushProductFlowLog('replaceProductsSnapshotInIndexDB.cleared', {
|
|
1913
|
-
source: source,
|
|
1914
|
-
inputCount: products.length
|
|
1915
|
-
});
|
|
1687
|
+
_context19.next = 4;
|
|
1688
|
+
return _this6.dbManager.clear(INDEXDB_STORE_NAME);
|
|
1689
|
+
case 4:
|
|
1916
1690
|
if (!(products.length > 0)) {
|
|
1917
|
-
_context19.next =
|
|
1691
|
+
_context19.next = 7;
|
|
1918
1692
|
break;
|
|
1919
1693
|
}
|
|
1920
|
-
_context19.next =
|
|
1921
|
-
return
|
|
1922
|
-
case
|
|
1923
|
-
writeSeq = _this7.trackProductWrite(source, 'clear+bulkUpdate', products, {}, 'snapshot');
|
|
1694
|
+
_context19.next = 7;
|
|
1695
|
+
return _this6.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
|
|
1696
|
+
case 7:
|
|
1924
1697
|
perfMark('replaceProductsSnapshotInIndexDB', performance.now() - t0, {
|
|
1925
1698
|
count: products.length
|
|
1926
1699
|
});
|
|
1927
|
-
|
|
1928
|
-
source: source,
|
|
1929
|
-
writeSeq: writeSeq,
|
|
1930
|
-
count: products.length
|
|
1931
|
-
});
|
|
1932
|
-
_this7.logInfo('replaceProductsSnapshotInIndexDB 完成', {
|
|
1700
|
+
_this6.logInfo('replaceProductsSnapshotInIndexDB 完成', {
|
|
1933
1701
|
source: source,
|
|
1934
1702
|
productCount: products.length
|
|
1935
1703
|
});
|
|
1936
|
-
case
|
|
1704
|
+
case 9:
|
|
1937
1705
|
case "end":
|
|
1938
1706
|
return _context19.stop();
|
|
1939
1707
|
}
|
|
1940
1708
|
}, _callee19);
|
|
1941
1709
|
})));
|
|
1942
|
-
case
|
|
1943
|
-
_context20.next =
|
|
1710
|
+
case 6:
|
|
1711
|
+
_context20.next = 12;
|
|
1944
1712
|
break;
|
|
1945
|
-
case
|
|
1946
|
-
_context20.prev =
|
|
1947
|
-
_context20.t0 = _context20["catch"](
|
|
1713
|
+
case 8:
|
|
1714
|
+
_context20.prev = 8;
|
|
1715
|
+
_context20.t0 = _context20["catch"](3);
|
|
1948
1716
|
errorMessage = _context20.t0 instanceof Error ? _context20.t0.message : String(_context20.t0);
|
|
1949
|
-
this.pushProductFlowLog('replaceProductsSnapshotInIndexDB.error', {
|
|
1950
|
-
source: source,
|
|
1951
|
-
productCount: products.length,
|
|
1952
|
-
error: errorMessage
|
|
1953
|
-
});
|
|
1954
1717
|
this.logError('全量保存商品到 IndexDB 失败', {
|
|
1955
1718
|
source: source,
|
|
1956
1719
|
productCount: products.length,
|
|
1957
1720
|
error: errorMessage
|
|
1958
1721
|
});
|
|
1959
|
-
case
|
|
1722
|
+
case 12:
|
|
1960
1723
|
case "end":
|
|
1961
1724
|
return _context20.stop();
|
|
1962
1725
|
}
|
|
1963
|
-
}, _callee20, this, [[
|
|
1726
|
+
}, _callee20, this, [[3, 8]]);
|
|
1964
1727
|
}));
|
|
1965
1728
|
function replaceProductsSnapshotInIndexDB(_x20, _x21) {
|
|
1966
1729
|
return _replaceProductsSnapshotInIndexDB.apply(this, arguments);
|
|
@@ -1978,7 +1741,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1978
1741
|
key: "patchProductsInIndexDB",
|
|
1979
1742
|
value: (function () {
|
|
1980
1743
|
var _patchProductsInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(products, source) {
|
|
1981
|
-
var
|
|
1744
|
+
var _this7 = this;
|
|
1982
1745
|
var mergeActions,
|
|
1983
1746
|
validProducts,
|
|
1984
1747
|
errorMessage,
|
|
@@ -1988,135 +1751,102 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1988
1751
|
case 0:
|
|
1989
1752
|
mergeActions = _args22.length > 2 && _args22[2] !== undefined ? _args22[2] : {};
|
|
1990
1753
|
if (!(!this.dbManager || products.length === 0)) {
|
|
1991
|
-
_context22.next =
|
|
1754
|
+
_context22.next = 3;
|
|
1992
1755
|
break;
|
|
1993
1756
|
}
|
|
1994
|
-
this.pushProductFlowLog('patchProductsInIndexDB.skip', {
|
|
1995
|
-
source: source,
|
|
1996
|
-
hasDbManager: !!this.dbManager,
|
|
1997
|
-
inputCount: products.length
|
|
1998
|
-
});
|
|
1999
1757
|
return _context22.abrupt("return");
|
|
2000
|
-
case
|
|
1758
|
+
case 3:
|
|
2001
1759
|
validProducts = products.filter(function (p) {
|
|
2002
1760
|
return (p === null || p === void 0 ? void 0 : p.id) !== undefined && (p === null || p === void 0 ? void 0 : p.id) !== null;
|
|
2003
1761
|
});
|
|
2004
1762
|
if (!(validProducts.length === 0)) {
|
|
2005
|
-
_context22.next =
|
|
1763
|
+
_context22.next = 6;
|
|
2006
1764
|
break;
|
|
2007
1765
|
}
|
|
2008
|
-
this.pushProductFlowLog('patchProductsInIndexDB.skipNoId', {
|
|
2009
|
-
source: source,
|
|
2010
|
-
inputCount: products.length
|
|
2011
|
-
});
|
|
2012
1766
|
return _context22.abrupt("return");
|
|
2013
|
-
case
|
|
2014
|
-
_context22.prev =
|
|
2015
|
-
_context22.next =
|
|
1767
|
+
case 6:
|
|
1768
|
+
_context22.prev = 6;
|
|
1769
|
+
_context22.next = 9;
|
|
2016
1770
|
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
|
|
2017
|
-
var
|
|
1771
|
+
var t0, _iterator10, _step10, product;
|
|
2018
1772
|
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
2019
1773
|
while (1) switch (_context21.prev = _context21.next) {
|
|
2020
1774
|
case 0:
|
|
2021
|
-
|
|
2022
|
-
_this8.pushProductFlowLog('patchProductsInIndexDB.start', {
|
|
2023
|
-
source: source,
|
|
2024
|
-
writeStrategy: 'bulkUpdate-patch',
|
|
2025
|
-
count: validProducts.length,
|
|
2026
|
-
productIds: validProducts.map(function (p) {
|
|
2027
|
-
return p.id;
|
|
2028
|
-
}),
|
|
2029
|
-
storeListCount: _this8.store.list.length
|
|
2030
|
-
});
|
|
2031
|
-
_this8.logInfo('patchProductsInIndexDB 开始', {
|
|
1775
|
+
_this7.logInfo('patchProductsInIndexDB 开始', {
|
|
2032
1776
|
source: source,
|
|
2033
1777
|
count: validProducts.length
|
|
2034
1778
|
});
|
|
2035
1779
|
t0 = performance.now();
|
|
2036
|
-
if (!(typeof
|
|
2037
|
-
_context21.next =
|
|
1780
|
+
if (!(typeof _this7.dbManager.bulkUpdate === 'function')) {
|
|
1781
|
+
_context21.next = 7;
|
|
2038
1782
|
break;
|
|
2039
1783
|
}
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
_context21.next = 29;
|
|
1784
|
+
_context21.next = 5;
|
|
1785
|
+
return _this7.dbManager.bulkUpdate(INDEXDB_STORE_NAME, validProducts);
|
|
1786
|
+
case 5:
|
|
1787
|
+
_context21.next = 25;
|
|
2045
1788
|
break;
|
|
2046
|
-
case
|
|
2047
|
-
if (!(typeof
|
|
2048
|
-
_context21.next =
|
|
1789
|
+
case 7:
|
|
1790
|
+
if (!(typeof _this7.dbManager.update === 'function')) {
|
|
1791
|
+
_context21.next = 25;
|
|
2049
1792
|
break;
|
|
2050
1793
|
}
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
_context21.next = 21;
|
|
1794
|
+
_iterator10 = _createForOfIteratorHelper(validProducts);
|
|
1795
|
+
_context21.prev = 9;
|
|
1796
|
+
_iterator10.s();
|
|
1797
|
+
case 11:
|
|
1798
|
+
if ((_step10 = _iterator10.n()).done) {
|
|
1799
|
+
_context21.next = 17;
|
|
2058
1800
|
break;
|
|
2059
1801
|
}
|
|
2060
|
-
product =
|
|
2061
|
-
_context21.next = 19;
|
|
2062
|
-
return _this8.dbManager.update(INDEXDB_STORE_NAME, product);
|
|
2063
|
-
case 19:
|
|
1802
|
+
product = _step10.value;
|
|
2064
1803
|
_context21.next = 15;
|
|
1804
|
+
return _this7.dbManager.update(INDEXDB_STORE_NAME, product);
|
|
1805
|
+
case 15:
|
|
1806
|
+
_context21.next = 11;
|
|
2065
1807
|
break;
|
|
2066
|
-
case
|
|
2067
|
-
_context21.next =
|
|
1808
|
+
case 17:
|
|
1809
|
+
_context21.next = 22;
|
|
2068
1810
|
break;
|
|
2069
|
-
case
|
|
2070
|
-
_context21.prev =
|
|
2071
|
-
_context21.t0 = _context21["catch"](
|
|
2072
|
-
|
|
2073
|
-
case
|
|
2074
|
-
_context21.prev =
|
|
2075
|
-
|
|
2076
|
-
return _context21.finish(
|
|
2077
|
-
case
|
|
2078
|
-
writeSeq = _this8.trackProductWrite(source, writeMethod, validProducts, mergeActions);
|
|
1811
|
+
case 19:
|
|
1812
|
+
_context21.prev = 19;
|
|
1813
|
+
_context21.t0 = _context21["catch"](9);
|
|
1814
|
+
_iterator10.e(_context21.t0);
|
|
1815
|
+
case 22:
|
|
1816
|
+
_context21.prev = 22;
|
|
1817
|
+
_iterator10.f();
|
|
1818
|
+
return _context21.finish(22);
|
|
1819
|
+
case 25:
|
|
2079
1820
|
perfMark('patchProductsInIndexDB', performance.now() - t0, {
|
|
2080
1821
|
count: validProducts.length
|
|
2081
1822
|
});
|
|
2082
|
-
|
|
2083
|
-
source: source,
|
|
2084
|
-
writeSeq: writeSeq,
|
|
2085
|
-
writeMethod: writeMethod,
|
|
2086
|
-
count: validProducts.length
|
|
2087
|
-
});
|
|
2088
|
-
_this8.logInfo('patchProductsInIndexDB 完成', {
|
|
1823
|
+
_this7.logInfo('patchProductsInIndexDB 完成', {
|
|
2089
1824
|
source: source,
|
|
2090
1825
|
count: validProducts.length
|
|
2091
1826
|
});
|
|
2092
|
-
case
|
|
1827
|
+
case 27:
|
|
2093
1828
|
case "end":
|
|
2094
1829
|
return _context21.stop();
|
|
2095
1830
|
}
|
|
2096
|
-
}, _callee21, null, [[
|
|
1831
|
+
}, _callee21, null, [[9, 19, 22, 25]]);
|
|
2097
1832
|
})));
|
|
2098
|
-
case
|
|
2099
|
-
_context22.next =
|
|
1833
|
+
case 9:
|
|
1834
|
+
_context22.next = 15;
|
|
2100
1835
|
break;
|
|
2101
|
-
case
|
|
2102
|
-
_context22.prev =
|
|
2103
|
-
_context22.t0 = _context22["catch"](
|
|
1836
|
+
case 11:
|
|
1837
|
+
_context22.prev = 11;
|
|
1838
|
+
_context22.t0 = _context22["catch"](6);
|
|
2104
1839
|
errorMessage = _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0);
|
|
2105
|
-
this.pushProductFlowLog('patchProductsInIndexDB.error', {
|
|
2106
|
-
source: source,
|
|
2107
|
-
error: errorMessage,
|
|
2108
|
-
productCount: validProducts.length
|
|
2109
|
-
});
|
|
2110
1840
|
this.logError('增量保存商品到 IndexDB 失败', {
|
|
2111
1841
|
source: source,
|
|
2112
1842
|
error: errorMessage,
|
|
2113
1843
|
productCount: validProducts.length
|
|
2114
1844
|
});
|
|
2115
|
-
case
|
|
1845
|
+
case 15:
|
|
2116
1846
|
case "end":
|
|
2117
1847
|
return _context22.stop();
|
|
2118
1848
|
}
|
|
2119
|
-
}, _callee22, this, [[
|
|
1849
|
+
}, _callee22, this, [[6, 11]]);
|
|
2120
1850
|
}));
|
|
2121
1851
|
function patchProductsInIndexDB(_x22, _x23) {
|
|
2122
1852
|
return _patchProductsInIndexDB.apply(this, arguments);
|
|
@@ -2134,17 +1864,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2134
1864
|
value: function syncProductsMap() {
|
|
2135
1865
|
var t0 = performance.now();
|
|
2136
1866
|
this.store.map.clear();
|
|
2137
|
-
var
|
|
2138
|
-
|
|
1867
|
+
var _iterator11 = _createForOfIteratorHelper(this.store.list),
|
|
1868
|
+
_step11;
|
|
2139
1869
|
try {
|
|
2140
|
-
for (
|
|
2141
|
-
var product =
|
|
1870
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
1871
|
+
var product = _step11.value;
|
|
2142
1872
|
this.store.map.set(product.id, product);
|
|
2143
1873
|
}
|
|
2144
1874
|
} catch (err) {
|
|
2145
|
-
|
|
1875
|
+
_iterator11.e(err);
|
|
2146
1876
|
} finally {
|
|
2147
|
-
|
|
1877
|
+
_iterator11.f();
|
|
2148
1878
|
}
|
|
2149
1879
|
perfMark('syncProductsMap', performance.now() - t0, {
|
|
2150
1880
|
count: this.store.map.size
|
|
@@ -2166,19 +1896,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2166
1896
|
case 0:
|
|
2167
1897
|
console.log('[Products] 开始预加载数据...');
|
|
2168
1898
|
tTotal = performance.now();
|
|
2169
|
-
this.pushProductFlowLog('preload.start', this.getProductStoreSnapshot());
|
|
2170
1899
|
this.logInfo('开始预加载数据');
|
|
2171
|
-
_context23.prev =
|
|
1900
|
+
_context23.prev = 3;
|
|
2172
1901
|
tIndexDB = performance.now();
|
|
2173
|
-
_context23.next =
|
|
1902
|
+
_context23.next = 7;
|
|
2174
1903
|
return this.loadProductsFromIndexDB();
|
|
2175
|
-
case
|
|
1904
|
+
case 7:
|
|
2176
1905
|
cachedData = _context23.sent;
|
|
2177
1906
|
perfMark('preload.loadFromIndexDB', performance.now() - tIndexDB, {
|
|
2178
1907
|
count: (_cachedData$length = cachedData === null || cachedData === void 0 ? void 0 : cachedData.length) !== null && _cachedData$length !== void 0 ? _cachedData$length : 0
|
|
2179
1908
|
});
|
|
2180
1909
|
if (!(cachedData && cachedData.length > 0)) {
|
|
2181
|
-
_context23.next =
|
|
1910
|
+
_context23.next = 20;
|
|
2182
1911
|
break;
|
|
2183
1912
|
}
|
|
2184
1913
|
console.log("[Products] \u4ECE IndexDB \u52A0\u8F7D\u4E86 ".concat(cachedData.length, " \u4E2A\u5546\u54C1"));
|
|
@@ -2199,30 +1928,26 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2199
1928
|
duration: "".concat(Math.round(performance.now() - tTotal), "ms"),
|
|
2200
1929
|
source: 'IndexDB'
|
|
2201
1930
|
});
|
|
2202
|
-
this.pushProductFlowLog('preload.done', _objectSpread({
|
|
2203
|
-
source: 'IndexDB',
|
|
2204
|
-
loadedCount: cachedData.length
|
|
2205
|
-
}, this.getProductStoreSnapshot()));
|
|
2206
1931
|
this.lastPreloadCompletedAtMs = Date.now();
|
|
2207
1932
|
return _context23.abrupt("return");
|
|
2208
|
-
case
|
|
1933
|
+
case 20:
|
|
2209
1934
|
console.log('[Products] IndexDB 中没有缓存数据,从服务器加载...');
|
|
2210
1935
|
this.logInfo('IndexDB 中没有缓存数据,准备从服务器加载');
|
|
2211
|
-
_context23.next =
|
|
1936
|
+
_context23.next = 29;
|
|
2212
1937
|
break;
|
|
2213
|
-
case
|
|
2214
|
-
_context23.prev =
|
|
2215
|
-
_context23.t0 = _context23["catch"](
|
|
1938
|
+
case 24:
|
|
1939
|
+
_context23.prev = 24;
|
|
1940
|
+
_context23.t0 = _context23["catch"](3);
|
|
2216
1941
|
errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0);
|
|
2217
1942
|
console.warn('[Products] 从 IndexDB 加载数据失败:', _context23.t0);
|
|
2218
1943
|
this.logWarning('从 IndexDB 加载数据失败,准备从服务器加载', {
|
|
2219
1944
|
error: errorMessage
|
|
2220
1945
|
});
|
|
2221
|
-
case
|
|
1946
|
+
case 29:
|
|
2222
1947
|
tServer = performance.now();
|
|
2223
|
-
_context23.next =
|
|
1948
|
+
_context23.next = 32;
|
|
2224
1949
|
return this.loadProductsByServer();
|
|
2225
|
-
case
|
|
1950
|
+
case 32:
|
|
2226
1951
|
products = _context23.sent;
|
|
2227
1952
|
perfMark('preload.loadFromServer', performance.now() - tServer, {
|
|
2228
1953
|
count: (_products$length3 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length3 !== void 0 ? _products$length3 : 0
|
|
@@ -2245,13 +1970,8 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2245
1970
|
duration: "".concat(Math.round(performance.now() - tTotal), "ms"),
|
|
2246
1971
|
source: 'Server'
|
|
2247
1972
|
});
|
|
2248
|
-
this.pushProductFlowLog('preload.done', _objectSpread({
|
|
2249
|
-
source: 'Server',
|
|
2250
|
-
loadedCount: products.length
|
|
2251
|
-
}, this.getProductStoreSnapshot()));
|
|
2252
1973
|
this.lastPreloadCompletedAtMs = Date.now();
|
|
2253
1974
|
} else {
|
|
2254
|
-
this.pushProductFlowLog('preload.empty', this.getProductStoreSnapshot());
|
|
2255
1975
|
perfMark('preload(empty)', performance.now() - tTotal, {
|
|
2256
1976
|
source: 'empty'
|
|
2257
1977
|
});
|
|
@@ -2259,11 +1979,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2259
1979
|
duration: "".concat(Math.round(performance.now() - tTotal), "ms")
|
|
2260
1980
|
});
|
|
2261
1981
|
}
|
|
2262
|
-
case
|
|
1982
|
+
case 35:
|
|
2263
1983
|
case "end":
|
|
2264
1984
|
return _context23.stop();
|
|
2265
1985
|
}
|
|
2266
|
-
}, _callee23, this, [[
|
|
1986
|
+
}, _callee23, this, [[3, 24]]);
|
|
2267
1987
|
}));
|
|
2268
1988
|
function preload() {
|
|
2269
1989
|
return _preload.apply(this, arguments);
|
|
@@ -2298,7 +2018,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2298
2018
|
}, {
|
|
2299
2019
|
key: "setupProductSync",
|
|
2300
2020
|
value: function setupProductSync() {
|
|
2301
|
-
var
|
|
2021
|
+
var _this8 = this;
|
|
2302
2022
|
if (!this.productDataSource) {
|
|
2303
2023
|
this.logWarning('setupProductSync: ProductDataSource 不可用,跳过同步初始化');
|
|
2304
2024
|
return;
|
|
@@ -2308,31 +2028,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2308
2028
|
var data = (message === null || message === void 0 ? void 0 : message.data) || message;
|
|
2309
2029
|
if (!data) return;
|
|
2310
2030
|
console.log("[ProductsModule] \u6536\u5230\u540C\u6B65\u6D88\u606F [".concat(channelKey, "]:"), data);
|
|
2311
|
-
|
|
2031
|
+
_this8.logInfo('收到同步消息', {
|
|
2312
2032
|
channelKey: channelKey,
|
|
2313
2033
|
action: data.action,
|
|
2314
2034
|
id: data.id,
|
|
2315
2035
|
action_filed: data.action_filed
|
|
2316
2036
|
});
|
|
2317
|
-
|
|
2037
|
+
_this8.pendingSyncMessages.push(_objectSpread(_objectSpread({}, data), {}, {
|
|
2318
2038
|
_channelKey: channelKey
|
|
2319
2039
|
}));
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
action: data.action,
|
|
2323
|
-
operation: data.operation,
|
|
2324
|
-
id: data.id,
|
|
2325
|
-
ids: data.ids,
|
|
2326
|
-
hasBody: !!data.body,
|
|
2327
|
-
changeTypes: data.change_types,
|
|
2328
|
-
pendingSyncCount: _this9.pendingSyncMessages.length,
|
|
2329
|
-
debounceMs: PRODUCT_SYNC_DEBOUNCE_MS
|
|
2330
|
-
});
|
|
2331
|
-
if (_this9.syncTimer) {
|
|
2332
|
-
clearTimeout(_this9.syncTimer);
|
|
2040
|
+
if (_this8.syncTimer) {
|
|
2041
|
+
clearTimeout(_this8.syncTimer);
|
|
2333
2042
|
}
|
|
2334
|
-
|
|
2335
|
-
|
|
2043
|
+
_this8.syncTimer = setTimeout(function () {
|
|
2044
|
+
_this8.processProductSyncMessages();
|
|
2336
2045
|
}, PRODUCT_SYNC_DEBOUNCE_MS);
|
|
2337
2046
|
};
|
|
2338
2047
|
};
|
|
@@ -2340,7 +2049,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2340
2049
|
pubsub: {
|
|
2341
2050
|
callback: function callback(res) {
|
|
2342
2051
|
console.log('sse_products_callback', res);
|
|
2343
|
-
|
|
2052
|
+
_this8.logInfo('sse_products_callback: 收到同步消息', {
|
|
2344
2053
|
data: res === null || res === void 0 ? void 0 : res.data
|
|
2345
2054
|
});
|
|
2346
2055
|
if (!(res !== null && res !== void 0 && res.data)) return;
|
|
@@ -2350,7 +2059,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2350
2059
|
}
|
|
2351
2060
|
}
|
|
2352
2061
|
}).catch(function (err) {
|
|
2353
|
-
|
|
2062
|
+
_this8.logError('setupProductSync: DataSource run 出错', {
|
|
2354
2063
|
error: err instanceof Error ? err.message : String(err)
|
|
2355
2064
|
});
|
|
2356
2065
|
});
|
|
@@ -2379,7 +2088,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2379
2088
|
key: "processProductSyncMessages",
|
|
2380
2089
|
value: (function () {
|
|
2381
2090
|
var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
|
|
2382
|
-
var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache,
|
|
2091
|
+
var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, shouldClearPriceCache, _iterator12, _step12, msg, channelKey, _msg$relation_product, _msg$change_types, _msg$ids2, _msg$ids, ids, bodyId, _bodyId, _msg$relation_product2, _msg$relation_product3, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, patchProductMap, patchMergeActions, storeMutated, bodyResult, _iterator13, _step13, product, freshProducts, mergeResult, _iterator14, _step14, _product, patchProducts, allChangedIds, hasChanges, errorMessage;
|
|
2383
2092
|
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
2384
2093
|
while (1) switch (_context24.prev = _context24.next) {
|
|
2385
2094
|
case 0:
|
|
@@ -2391,9 +2100,6 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2391
2100
|
}
|
|
2392
2101
|
return _context24.abrupt("return");
|
|
2393
2102
|
case 4:
|
|
2394
|
-
this.pushProductFlowLog('processProductSyncMessages.start', _objectSpread({
|
|
2395
|
-
messageCount: messages.length
|
|
2396
|
-
}, this.getProductStoreSnapshot()));
|
|
2397
2103
|
this.logInfo('processProductSyncMessages: 开始处理', {
|
|
2398
2104
|
count: messages.length
|
|
2399
2105
|
});
|
|
@@ -2402,18 +2108,18 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2402
2108
|
sseRefreshIds = [];
|
|
2403
2109
|
priceRefreshIds = [];
|
|
2404
2110
|
shouldClearPriceCache = false;
|
|
2405
|
-
|
|
2406
|
-
_context24.prev =
|
|
2407
|
-
|
|
2408
|
-
case
|
|
2409
|
-
if ((
|
|
2410
|
-
_context24.next =
|
|
2111
|
+
_iterator12 = _createForOfIteratorHelper(messages);
|
|
2112
|
+
_context24.prev = 11;
|
|
2113
|
+
_iterator12.s();
|
|
2114
|
+
case 13:
|
|
2115
|
+
if ((_step12 = _iterator12.n()).done) {
|
|
2116
|
+
_context24.next = 36;
|
|
2411
2117
|
break;
|
|
2412
2118
|
}
|
|
2413
|
-
msg =
|
|
2119
|
+
msg = _step12.value;
|
|
2414
2120
|
channelKey = msg._channelKey || msg.module || 'product';
|
|
2415
2121
|
if (!(channelKey === 'product')) {
|
|
2416
|
-
_context24.next =
|
|
2122
|
+
_context24.next = 33;
|
|
2417
2123
|
break;
|
|
2418
2124
|
}
|
|
2419
2125
|
if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
|
|
@@ -2421,14 +2127,14 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2421
2127
|
}
|
|
2422
2128
|
// 1. 删除场景:operation === 'delete' 或 action === 'delete'
|
|
2423
2129
|
if (!(msg.operation === 'delete' || msg.action === 'delete')) {
|
|
2424
|
-
_context24.next =
|
|
2130
|
+
_context24.next = 21;
|
|
2425
2131
|
break;
|
|
2426
2132
|
}
|
|
2427
2133
|
if ((_msg$ids = msg.ids) !== null && _msg$ids !== void 0 && _msg$ids.length) deleteIds.push.apply(deleteIds, _toConsumableArray(msg.ids));else if (msg.id) deleteIds.push(msg.id);
|
|
2428
|
-
return _context24.abrupt("continue",
|
|
2429
|
-
case
|
|
2134
|
+
return _context24.abrupt("continue", 34);
|
|
2135
|
+
case 21:
|
|
2430
2136
|
if (!((_msg$change_types = msg.change_types) !== null && _msg$change_types !== void 0 && _msg$change_types.includes('price'))) {
|
|
2431
|
-
_context24.next =
|
|
2137
|
+
_context24.next = 26;
|
|
2432
2138
|
break;
|
|
2433
2139
|
}
|
|
2434
2140
|
ids = msg.ids || (msg.id ? [msg.id] : []);
|
|
@@ -2437,25 +2143,25 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2437
2143
|
bodyId = msg.body.id;
|
|
2438
2144
|
if (bodyId) bodyUpdates.set(bodyId, msg.body);
|
|
2439
2145
|
}
|
|
2440
|
-
return _context24.abrupt("continue",
|
|
2441
|
-
case
|
|
2146
|
+
return _context24.abrupt("continue", 34);
|
|
2147
|
+
case 26:
|
|
2442
2148
|
if (!msg.body) {
|
|
2443
|
-
_context24.next =
|
|
2149
|
+
_context24.next = 30;
|
|
2444
2150
|
break;
|
|
2445
2151
|
}
|
|
2446
2152
|
_bodyId = msg.body.id || msg.id;
|
|
2447
2153
|
if (_bodyId) bodyUpdates.set(_bodyId, msg.body);
|
|
2448
|
-
return _context24.abrupt("continue",
|
|
2449
|
-
case
|
|
2154
|
+
return _context24.abrupt("continue", 34);
|
|
2155
|
+
case 30:
|
|
2450
2156
|
// 4. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
|
|
2451
2157
|
if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
|
|
2452
2158
|
sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.ids));
|
|
2453
2159
|
} else if (msg.id) {
|
|
2454
2160
|
sseRefreshIds.push(msg.id);
|
|
2455
2161
|
}
|
|
2456
|
-
_context24.next =
|
|
2162
|
+
_context24.next = 34;
|
|
2457
2163
|
break;
|
|
2458
|
-
case
|
|
2164
|
+
case 33:
|
|
2459
2165
|
if (channelKey === 'product_quotation') {
|
|
2460
2166
|
// 报价单变更影响范围大,标记清除全量价格缓存
|
|
2461
2167
|
shouldClearPriceCache = true;
|
|
@@ -2467,124 +2173,108 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2467
2173
|
sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_product_ids));
|
|
2468
2174
|
}
|
|
2469
2175
|
}
|
|
2470
|
-
case
|
|
2471
|
-
_context24.next =
|
|
2176
|
+
case 34:
|
|
2177
|
+
_context24.next = 13;
|
|
2472
2178
|
break;
|
|
2473
|
-
case
|
|
2474
|
-
_context24.next =
|
|
2179
|
+
case 36:
|
|
2180
|
+
_context24.next = 41;
|
|
2475
2181
|
break;
|
|
2476
|
-
case
|
|
2477
|
-
_context24.prev =
|
|
2478
|
-
_context24.t0 = _context24["catch"](
|
|
2479
|
-
|
|
2480
|
-
case
|
|
2481
|
-
_context24.prev =
|
|
2482
|
-
|
|
2483
|
-
return _context24.finish(
|
|
2484
|
-
case
|
|
2182
|
+
case 38:
|
|
2183
|
+
_context24.prev = 38;
|
|
2184
|
+
_context24.t0 = _context24["catch"](11);
|
|
2185
|
+
_iterator12.e(_context24.t0);
|
|
2186
|
+
case 41:
|
|
2187
|
+
_context24.prev = 41;
|
|
2188
|
+
_iterator12.f();
|
|
2189
|
+
return _context24.finish(41);
|
|
2190
|
+
case 44:
|
|
2485
2191
|
uniqueDeleteIds = _toConsumableArray(new Set(deleteIds));
|
|
2486
2192
|
uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds));
|
|
2487
|
-
uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds));
|
|
2488
|
-
this.pushProductFlowLog('processProductSyncMessages.parsed', {
|
|
2489
|
-
deleteIds: uniqueDeleteIds,
|
|
2490
|
-
bodyUpdateIds: _toConsumableArray(bodyUpdates.keys()),
|
|
2491
|
-
sseRefreshIds: uniqueSSEIds,
|
|
2492
|
-
priceRefreshIds: uniquePriceIds,
|
|
2493
|
-
shouldClearPriceCache: shouldClearPriceCache
|
|
2494
|
-
});
|
|
2495
|
-
|
|
2496
|
-
// 1. 处理删除
|
|
2193
|
+
uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds)); // 1. 处理删除
|
|
2497
2194
|
if (!(uniqueDeleteIds.length > 0)) {
|
|
2498
|
-
_context24.next =
|
|
2195
|
+
_context24.next = 50;
|
|
2499
2196
|
break;
|
|
2500
2197
|
}
|
|
2501
|
-
_context24.next =
|
|
2198
|
+
_context24.next = 50;
|
|
2502
2199
|
return this.removeProductsByIds(uniqueDeleteIds);
|
|
2503
|
-
case
|
|
2200
|
+
case 50:
|
|
2504
2201
|
/** 本批次待 patch 的商品(按 id 去重,SSE 覆盖 body) */
|
|
2505
2202
|
patchProductMap = new Map();
|
|
2506
2203
|
patchMergeActions = {};
|
|
2507
2204
|
storeMutated = uniqueDeleteIds.length > 0; // 2. 处理 body 直接覆盖(仅内存,IndexDB 批次末统一 patch)
|
|
2508
2205
|
if (!(bodyUpdates.size > 0)) {
|
|
2509
|
-
_context24.next =
|
|
2206
|
+
_context24.next = 60;
|
|
2510
2207
|
break;
|
|
2511
2208
|
}
|
|
2512
|
-
_context24.next =
|
|
2209
|
+
_context24.next = 56;
|
|
2513
2210
|
return this.applyBodyUpdatesToStore(bodyUpdates, {
|
|
2514
2211
|
skipIndexDB: true,
|
|
2515
2212
|
skipEmit: true
|
|
2516
2213
|
});
|
|
2517
|
-
case
|
|
2214
|
+
case 56:
|
|
2518
2215
|
bodyResult = _context24.sent;
|
|
2519
|
-
|
|
2216
|
+
_iterator13 = _createForOfIteratorHelper(bodyResult.changedProducts);
|
|
2520
2217
|
try {
|
|
2521
|
-
for (
|
|
2522
|
-
product =
|
|
2218
|
+
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
2219
|
+
product = _step13.value;
|
|
2523
2220
|
patchProductMap.set(product.id, product);
|
|
2524
2221
|
patchMergeActions[product.id] = bodyResult.mergeActions[product.id];
|
|
2525
2222
|
}
|
|
2526
2223
|
} catch (err) {
|
|
2527
|
-
|
|
2224
|
+
_iterator13.e(err);
|
|
2528
2225
|
} finally {
|
|
2529
|
-
|
|
2226
|
+
_iterator13.f();
|
|
2530
2227
|
}
|
|
2531
2228
|
storeMutated = true;
|
|
2532
|
-
case
|
|
2229
|
+
case 60:
|
|
2533
2230
|
// 3. 处理 SSE 增量拉取(仅内存,IndexDB 批次末统一 patch)
|
|
2534
2231
|
freshProducts = [];
|
|
2535
2232
|
if (!(uniqueSSEIds.length > 0)) {
|
|
2536
|
-
_context24.next =
|
|
2233
|
+
_context24.next = 73;
|
|
2537
2234
|
break;
|
|
2538
2235
|
}
|
|
2539
|
-
_context24.next =
|
|
2236
|
+
_context24.next = 64;
|
|
2540
2237
|
return this.fetchProductsBySSE(uniqueSSEIds);
|
|
2541
|
-
case
|
|
2238
|
+
case 64:
|
|
2542
2239
|
freshProducts = _context24.sent;
|
|
2543
2240
|
if (!(freshProducts.length > 0)) {
|
|
2544
|
-
_context24.next =
|
|
2241
|
+
_context24.next = 72;
|
|
2545
2242
|
break;
|
|
2546
2243
|
}
|
|
2547
|
-
_context24.next =
|
|
2244
|
+
_context24.next = 68;
|
|
2548
2245
|
return this.mergeProductsToStore(freshProducts, {
|
|
2549
2246
|
skipIndexDB: true,
|
|
2550
2247
|
skipEmit: true
|
|
2551
2248
|
});
|
|
2552
|
-
case
|
|
2249
|
+
case 68:
|
|
2553
2250
|
mergeResult = _context24.sent;
|
|
2554
|
-
|
|
2251
|
+
_iterator14 = _createForOfIteratorHelper(mergeResult.changedProducts);
|
|
2555
2252
|
try {
|
|
2556
|
-
for (
|
|
2557
|
-
_product =
|
|
2253
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
2254
|
+
_product = _step14.value;
|
|
2558
2255
|
patchProductMap.set(_product.id, _product);
|
|
2559
2256
|
patchMergeActions[_product.id] = mergeResult.mergeActions[_product.id];
|
|
2560
2257
|
}
|
|
2561
2258
|
} catch (err) {
|
|
2562
|
-
|
|
2259
|
+
_iterator14.e(err);
|
|
2563
2260
|
} finally {
|
|
2564
|
-
|
|
2261
|
+
_iterator14.f();
|
|
2565
2262
|
}
|
|
2566
2263
|
storeMutated = true;
|
|
2567
|
-
case
|
|
2264
|
+
case 72:
|
|
2568
2265
|
this.logInfo('processProductSyncMessages: SSE 增量更新完成123', {
|
|
2569
2266
|
requestedCount: uniqueSSEIds.length,
|
|
2570
2267
|
receivedCount: freshProducts.length
|
|
2571
2268
|
});
|
|
2572
|
-
case
|
|
2269
|
+
case 73:
|
|
2573
2270
|
patchProducts = _toConsumableArray(patchProductMap.values());
|
|
2574
2271
|
if (!(patchProducts.length > 0)) {
|
|
2575
|
-
_context24.next =
|
|
2272
|
+
_context24.next = 77;
|
|
2576
2273
|
break;
|
|
2577
2274
|
}
|
|
2578
|
-
_context24.next =
|
|
2275
|
+
_context24.next = 77;
|
|
2579
2276
|
return this.patchProductsInIndexDB(patchProducts, 'pubsub.processProductSyncMessages', patchMergeActions);
|
|
2580
|
-
case
|
|
2581
|
-
this.pushProductFlowLog('processProductSyncMessages.patchDone', {
|
|
2582
|
-
patchCount: patchProducts.length,
|
|
2583
|
-
patchProductIds: patchProducts.map(function (p) {
|
|
2584
|
-
return p.id;
|
|
2585
|
-
})
|
|
2586
|
-
});
|
|
2587
|
-
case 80:
|
|
2277
|
+
case 77:
|
|
2588
2278
|
if (storeMutated) {
|
|
2589
2279
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
2590
2280
|
}
|
|
@@ -2601,50 +2291,41 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2601
2291
|
});
|
|
2602
2292
|
hasChanges = uniqueDeleteIds.length > 0 || allChangedIds.length > 0 || shouldClearPriceCache;
|
|
2603
2293
|
if (hasChanges) {
|
|
2604
|
-
_context24.next =
|
|
2294
|
+
_context24.next = 84;
|
|
2605
2295
|
break;
|
|
2606
2296
|
}
|
|
2607
|
-
this.pushProductFlowLog('processProductSyncMessages.noChanges', {});
|
|
2608
2297
|
this.logInfo('processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted');
|
|
2609
2298
|
return _context24.abrupt("return");
|
|
2610
|
-
case
|
|
2299
|
+
case 84:
|
|
2611
2300
|
if (!shouldClearPriceCache) {
|
|
2612
|
-
_context24.next =
|
|
2301
|
+
_context24.next = 95;
|
|
2613
2302
|
break;
|
|
2614
2303
|
}
|
|
2615
|
-
_context24.prev =
|
|
2616
|
-
_context24.next =
|
|
2304
|
+
_context24.prev = 85;
|
|
2305
|
+
_context24.next = 88;
|
|
2617
2306
|
return this.refreshQuotationPriceBridge();
|
|
2618
|
-
case
|
|
2619
|
-
_context24.next =
|
|
2307
|
+
case 88:
|
|
2308
|
+
_context24.next = 94;
|
|
2620
2309
|
break;
|
|
2621
|
-
case
|
|
2622
|
-
_context24.prev =
|
|
2623
|
-
_context24.t1 = _context24["catch"](
|
|
2310
|
+
case 90:
|
|
2311
|
+
_context24.prev = 90;
|
|
2312
|
+
_context24.t1 = _context24["catch"](85);
|
|
2624
2313
|
errorMessage = _context24.t1 instanceof Error ? _context24.t1.message : String(_context24.t1);
|
|
2625
2314
|
this.logError('报价单桥接刷新失败,将继续清理价格缓存', {
|
|
2626
2315
|
error: errorMessage
|
|
2627
2316
|
});
|
|
2628
|
-
case
|
|
2317
|
+
case 94:
|
|
2629
2318
|
this.clearPriceCache();
|
|
2630
|
-
case
|
|
2631
|
-
_context24.next =
|
|
2319
|
+
case 95:
|
|
2320
|
+
_context24.next = 97;
|
|
2632
2321
|
return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, {
|
|
2633
2322
|
changedIds: allChangedIds
|
|
2634
2323
|
});
|
|
2635
|
-
case
|
|
2636
|
-
this.pushProductFlowLog('processProductSyncMessages.done', _objectSpread({
|
|
2637
|
-
deleteCount: uniqueDeleteIds.length,
|
|
2638
|
-
bodyUpdateCount: bodyUpdates.size,
|
|
2639
|
-
sseRefreshCount: uniqueSSEIds.length,
|
|
2640
|
-
allChangedIds: allChangedIds,
|
|
2641
|
-
shouldClearPriceCache: shouldClearPriceCache
|
|
2642
|
-
}, this.getProductStoreSnapshot()));
|
|
2643
|
-
case 102:
|
|
2324
|
+
case 97:
|
|
2644
2325
|
case "end":
|
|
2645
2326
|
return _context24.stop();
|
|
2646
2327
|
}
|
|
2647
|
-
}, _callee24, this, [[
|
|
2328
|
+
}, _callee24, this, [[11, 38, 41, 44], [85, 90]]);
|
|
2648
2329
|
}));
|
|
2649
2330
|
function processProductSyncMessages() {
|
|
2650
2331
|
return _processProductSyncMessages.apply(this, arguments);
|
|
@@ -2730,16 +2411,11 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2730
2411
|
key: "applyBodyUpdatesToStore",
|
|
2731
2412
|
value: (function () {
|
|
2732
2413
|
var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(bodyUpdates, options) {
|
|
2733
|
-
var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts,
|
|
2414
|
+
var changedProductIds, updatedCount, newCount, appliedIds, mergeActions, changedProducts, _iterator15, _step15, _step15$value, id, body;
|
|
2734
2415
|
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
2735
2416
|
while (1) switch (_context26.prev = _context26.next) {
|
|
2736
2417
|
case 0:
|
|
2737
2418
|
changedProductIds = _toConsumableArray(bodyUpdates.keys());
|
|
2738
|
-
this.pushProductFlowLog('applyBodyUpdatesToStore.start', _objectSpread({
|
|
2739
|
-
changedProductIds: changedProductIds,
|
|
2740
|
-
count: bodyUpdates.size,
|
|
2741
|
-
skipIndexDB: !!(options !== null && options !== void 0 && options.skipIndexDB)
|
|
2742
|
-
}, this.getProductStoreSnapshot()));
|
|
2743
2419
|
this.logInfo('applyBodyUpdatesToStore: 开始', {
|
|
2744
2420
|
count: bodyUpdates.size
|
|
2745
2421
|
});
|
|
@@ -2759,10 +2435,10 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2759
2435
|
}
|
|
2760
2436
|
return p;
|
|
2761
2437
|
});
|
|
2762
|
-
|
|
2438
|
+
_iterator15 = _createForOfIteratorHelper(bodyUpdates);
|
|
2763
2439
|
try {
|
|
2764
|
-
for (
|
|
2765
|
-
|
|
2440
|
+
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
2441
|
+
_step15$value = _slicedToArray(_step15.value, 2), id = _step15$value[0], body = _step15$value[1];
|
|
2766
2442
|
if (!appliedIds.has(id)) {
|
|
2767
2443
|
this.store.list.push(body);
|
|
2768
2444
|
newCount++;
|
|
@@ -2771,28 +2447,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2771
2447
|
}
|
|
2772
2448
|
}
|
|
2773
2449
|
} catch (err) {
|
|
2774
|
-
|
|
2450
|
+
_iterator15.e(err);
|
|
2775
2451
|
} finally {
|
|
2776
|
-
|
|
2452
|
+
_iterator15.f();
|
|
2777
2453
|
}
|
|
2778
2454
|
this.syncProductsMap();
|
|
2779
2455
|
if (options !== null && options !== void 0 && options.skipIndexDB) {
|
|
2780
|
-
_context26.next =
|
|
2456
|
+
_context26.next = 14;
|
|
2781
2457
|
break;
|
|
2782
2458
|
}
|
|
2783
|
-
_context26.next =
|
|
2459
|
+
_context26.next = 14;
|
|
2784
2460
|
return this.patchProductsInIndexDB(changedProducts, 'pubsub.bodyUpdate', mergeActions);
|
|
2785
|
-
case
|
|
2461
|
+
case 14:
|
|
2786
2462
|
if (!(options !== null && options !== void 0 && options.skipEmit)) {
|
|
2787
2463
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
2788
2464
|
}
|
|
2789
|
-
this.pushProductFlowLog('applyBodyUpdatesToStore.done', {
|
|
2790
|
-
changedProductIds: changedProductIds,
|
|
2791
|
-
updatedCount: updatedCount,
|
|
2792
|
-
newCount: newCount,
|
|
2793
|
-
totalCount: this.store.list.length,
|
|
2794
|
-
indexDbPatchCount: options !== null && options !== void 0 && options.skipIndexDB ? 0 : changedProducts.length
|
|
2795
|
-
});
|
|
2796
2465
|
this.logInfo('applyBodyUpdatesToStore: 完成', {
|
|
2797
2466
|
updatedCount: updatedCount,
|
|
2798
2467
|
newCount: newCount,
|
|
@@ -2804,7 +2473,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2804
2473
|
updatedCount: updatedCount,
|
|
2805
2474
|
newCount: newCount
|
|
2806
2475
|
});
|
|
2807
|
-
case
|
|
2476
|
+
case 17:
|
|
2808
2477
|
case "end":
|
|
2809
2478
|
return _context26.stop();
|
|
2810
2479
|
}
|
|
@@ -2827,21 +2496,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2827
2496
|
key: "mergeProductsToStore",
|
|
2828
2497
|
value: (function () {
|
|
2829
2498
|
var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(freshProducts, options) {
|
|
2830
|
-
var freshMap,
|
|
2499
|
+
var freshMap, _iterator16, _step16, p, mergeActions, changedProducts, updatedList, newCount, _iterator17, _step17, _p2, updatedCount, changedProductIds;
|
|
2831
2500
|
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
2832
2501
|
while (1) switch (_context27.prev = _context27.next) {
|
|
2833
2502
|
case 0:
|
|
2834
2503
|
freshMap = new Map();
|
|
2835
|
-
|
|
2504
|
+
_iterator16 = _createForOfIteratorHelper(freshProducts);
|
|
2836
2505
|
try {
|
|
2837
|
-
for (
|
|
2838
|
-
p =
|
|
2506
|
+
for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
|
|
2507
|
+
p = _step16.value;
|
|
2839
2508
|
freshMap.set(p.id, p);
|
|
2840
2509
|
}
|
|
2841
2510
|
} catch (err) {
|
|
2842
|
-
|
|
2511
|
+
_iterator16.e(err);
|
|
2843
2512
|
} finally {
|
|
2844
|
-
|
|
2513
|
+
_iterator16.f();
|
|
2845
2514
|
}
|
|
2846
2515
|
mergeActions = {};
|
|
2847
2516
|
changedProducts = [];
|
|
@@ -2856,47 +2525,35 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2856
2525
|
return p;
|
|
2857
2526
|
}); // freshMap 中剩余的是新商品(create 场景)
|
|
2858
2527
|
newCount = freshMap.size;
|
|
2859
|
-
|
|
2528
|
+
_iterator17 = _createForOfIteratorHelper(freshMap.values());
|
|
2860
2529
|
try {
|
|
2861
|
-
for (
|
|
2862
|
-
_p2 =
|
|
2530
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
2531
|
+
_p2 = _step17.value;
|
|
2863
2532
|
updatedList.push(_p2);
|
|
2864
2533
|
mergeActions[_p2.id] = 'insert';
|
|
2865
2534
|
changedProducts.push(_p2);
|
|
2866
2535
|
}
|
|
2867
2536
|
} catch (err) {
|
|
2868
|
-
|
|
2537
|
+
_iterator17.e(err);
|
|
2869
2538
|
} finally {
|
|
2870
|
-
|
|
2539
|
+
_iterator17.f();
|
|
2871
2540
|
}
|
|
2872
2541
|
updatedCount = freshProducts.length - newCount;
|
|
2873
2542
|
changedProductIds = freshProducts.map(function (p) {
|
|
2874
2543
|
return p.id;
|
|
2875
2544
|
});
|
|
2876
|
-
this.pushProductFlowLog('mergeProductsToStore.start', _objectSpread({
|
|
2877
|
-
changedProductIds: changedProductIds,
|
|
2878
|
-
incomingCount: freshProducts.length,
|
|
2879
|
-
skipIndexDB: !!(options !== null && options !== void 0 && options.skipIndexDB)
|
|
2880
|
-
}, this.getProductStoreSnapshot()));
|
|
2881
2545
|
this.store.list = updatedList;
|
|
2882
2546
|
this.syncProductsMap();
|
|
2883
2547
|
if (options !== null && options !== void 0 && options.skipIndexDB) {
|
|
2884
|
-
_context27.next =
|
|
2548
|
+
_context27.next = 16;
|
|
2885
2549
|
break;
|
|
2886
2550
|
}
|
|
2887
|
-
_context27.next =
|
|
2551
|
+
_context27.next = 16;
|
|
2888
2552
|
return this.patchProductsInIndexDB(changedProducts, 'pubsub.mergeProductsToStore', mergeActions);
|
|
2889
|
-
case
|
|
2553
|
+
case 16:
|
|
2890
2554
|
if (!(options !== null && options !== void 0 && options.skipEmit)) {
|
|
2891
2555
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
2892
2556
|
}
|
|
2893
|
-
this.pushProductFlowLog('mergeProductsToStore.done', {
|
|
2894
|
-
changedProductIds: changedProductIds,
|
|
2895
|
-
updatedCount: updatedCount,
|
|
2896
|
-
newCount: newCount,
|
|
2897
|
-
totalCount: this.store.list.length,
|
|
2898
|
-
indexDbPatchCount: options !== null && options !== void 0 && options.skipIndexDB ? 0 : changedProducts.length
|
|
2899
|
-
});
|
|
2900
2557
|
this.logInfo('mergeProductsToStore: 合并完成', {
|
|
2901
2558
|
updatedCount: updatedCount,
|
|
2902
2559
|
newCount: newCount,
|
|
@@ -2908,7 +2565,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2908
2565
|
updatedCount: updatedCount,
|
|
2909
2566
|
newCount: newCount
|
|
2910
2567
|
});
|
|
2911
|
-
case
|
|
2568
|
+
case 19:
|
|
2912
2569
|
case "end":
|
|
2913
2570
|
return _context27.stop();
|
|
2914
2571
|
}
|
|
@@ -2938,71 +2595,55 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2938
2595
|
elapsedSincePreload = now - this.lastPreloadCompletedAtMs;
|
|
2939
2596
|
elapsedSinceFullFetch = now - this.lastServerFullFetchAtMs;
|
|
2940
2597
|
if (!(this.lastPreloadCompletedAtMs > 0 && elapsedSincePreload < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS)) {
|
|
2941
|
-
_context28.next =
|
|
2598
|
+
_context28.next = 6;
|
|
2942
2599
|
break;
|
|
2943
2600
|
}
|
|
2944
|
-
this.pushProductFlowLog('silentRefresh.skipped', _objectSpread({
|
|
2945
|
-
elapsedSincePreloadMs: this.lastPreloadCompletedAtMs > 0 ? elapsedSincePreload : null,
|
|
2946
|
-
elapsedSinceFullFetchMs: this.lastServerFullFetchAtMs > 0 ? elapsedSinceFullFetch : null,
|
|
2947
|
-
minIntervalMs: PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS
|
|
2948
|
-
}, this.getProductStoreSnapshot()));
|
|
2949
2601
|
return _context28.abrupt("return", this.store.list);
|
|
2950
|
-
case
|
|
2951
|
-
this.pushProductFlowLog('silentRefresh.start', _objectSpread({
|
|
2952
|
-
note: '会调用 loadProductsByServer → replaceProductsSnapshotInIndexDB'
|
|
2953
|
-
}, this.getProductStoreSnapshot()));
|
|
2602
|
+
case 6:
|
|
2954
2603
|
this.logInfo('silentRefresh 开始');
|
|
2955
|
-
_context28.prev =
|
|
2956
|
-
_context28.next =
|
|
2604
|
+
_context28.prev = 7;
|
|
2605
|
+
_context28.next = 10;
|
|
2957
2606
|
return this.loadProductsByServer();
|
|
2958
|
-
case
|
|
2607
|
+
case 10:
|
|
2959
2608
|
products = _context28.sent;
|
|
2960
2609
|
if (!(products && products.length > 0)) {
|
|
2961
|
-
_context28.next =
|
|
2610
|
+
_context28.next = 21;
|
|
2962
2611
|
break;
|
|
2963
2612
|
}
|
|
2964
2613
|
this.store.list = products;
|
|
2965
2614
|
this.syncProductsMap();
|
|
2966
2615
|
this.clearPriceCache();
|
|
2967
2616
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
2968
|
-
_context28.next =
|
|
2617
|
+
_context28.next = 18;
|
|
2969
2618
|
return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
|
|
2970
|
-
case
|
|
2971
|
-
this.pushProductFlowLog('silentRefresh.done', _objectSpread({
|
|
2972
|
-
productCount: products.length,
|
|
2973
|
-
durationMs: Math.round(performance.now() - t0)
|
|
2974
|
-
}, this.getProductStoreSnapshot()));
|
|
2619
|
+
case 18:
|
|
2975
2620
|
this.logInfo('silentRefresh 完成', {
|
|
2976
2621
|
productCount: products.length,
|
|
2977
2622
|
duration: "".concat(Math.round(performance.now() - t0), "ms")
|
|
2978
2623
|
});
|
|
2979
|
-
_context28.next =
|
|
2624
|
+
_context28.next = 22;
|
|
2980
2625
|
break;
|
|
2981
|
-
case
|
|
2982
|
-
this.pushProductFlowLog('silentRefresh.empty', {});
|
|
2626
|
+
case 21:
|
|
2983
2627
|
this.logWarning('silentRefresh: 服务器未返回数据');
|
|
2984
|
-
case
|
|
2628
|
+
case 22:
|
|
2985
2629
|
perfMark('silentRefresh', performance.now() - t0, {
|
|
2986
2630
|
count: this.store.list.length
|
|
2987
2631
|
});
|
|
2988
2632
|
return _context28.abrupt("return", this.store.list);
|
|
2989
|
-
case
|
|
2990
|
-
_context28.prev =
|
|
2991
|
-
_context28.t0 = _context28["catch"](
|
|
2633
|
+
case 26:
|
|
2634
|
+
_context28.prev = 26;
|
|
2635
|
+
_context28.t0 = _context28["catch"](7);
|
|
2992
2636
|
errorMessage = _context28.t0 instanceof Error ? _context28.t0.message : String(_context28.t0);
|
|
2993
|
-
this.pushProductFlowLog('silentRefresh.failed', {
|
|
2994
|
-
error: errorMessage
|
|
2995
|
-
});
|
|
2996
2637
|
this.logError('silentRefresh 失败', {
|
|
2997
2638
|
duration: "".concat(Math.round(performance.now() - t0), "ms"),
|
|
2998
2639
|
error: errorMessage
|
|
2999
2640
|
});
|
|
3000
2641
|
return _context28.abrupt("return", this.store.list);
|
|
3001
|
-
case
|
|
2642
|
+
case 31:
|
|
3002
2643
|
case "end":
|
|
3003
2644
|
return _context28.stop();
|
|
3004
2645
|
}
|
|
3005
|
-
}, _callee28, this, [[
|
|
2646
|
+
}, _callee28, this, [[7, 26]]);
|
|
3006
2647
|
}));
|
|
3007
2648
|
function silentRefresh() {
|
|
3008
2649
|
return _silentRefresh.apply(this, arguments);
|