@pisell/pisellos 2.2.85 → 2.2.87

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.
@@ -1124,7 +1124,7 @@ var Server = /*#__PURE__*/function () {
1124
1124
  var _computeProductQueryResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(context) {
1125
1125
  var _menu_list_ids$length3,
1126
1126
  _this5 = this;
1127
- var tTotal, menu_list_ids, schedule_date, schedule_datetime, activeMenuList, tMenu, menuList, tPrice, allProductsWithPrice, tFilter, filteredProducts, tSort;
1127
+ var tTotal, menu_list_ids, schedule_date, schedule_datetime, activeMenuList, tMenu, menuList, tPrice, allProductsWithPrice, tFilter, filteredProducts, tStatus, beforeStatusCount, tSort;
1128
1128
  return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1129
1129
  while (1) switch (_context12.prev = _context12.next) {
1130
1130
  case 0:
@@ -1203,6 +1203,15 @@ var Server = /*#__PURE__*/function () {
1203
1203
  before: allProductsWithPrice.length,
1204
1204
  after: filteredProducts.length
1205
1205
  });
1206
+ tStatus = performance.now();
1207
+ beforeStatusCount = filteredProducts.length;
1208
+ filteredProducts = filteredProducts.filter(function (p) {
1209
+ return ((p === null || p === void 0 ? void 0 : p.status) || "published") === 'published';
1210
+ });
1211
+ perfMark('computeQuery.filterByStatus', performance.now() - tStatus, {
1212
+ before: beforeStatusCount,
1213
+ after: filteredProducts.length
1214
+ });
1206
1215
  tSort = performance.now();
1207
1216
  filteredProducts = filteredProducts.sort(function (a, b) {
1208
1217
  var sortDiff = Number(b.sort) - Number(a.sort);
@@ -1231,7 +1240,7 @@ var Server = /*#__PURE__*/function () {
1231
1240
  message: '',
1232
1241
  status: true
1233
1242
  });
1234
- case 28:
1243
+ case 32:
1235
1244
  case "end":
1236
1245
  return _context12.stop();
1237
1246
  }
@@ -157,8 +157,8 @@ export declare class ProductsModule extends BaseModule implements Module {
157
157
  */
158
158
  refreshProducts(): Promise<ProductData[]>;
159
159
  /**
160
- * 局部更新指定商品的报价单价格
161
- * 遍历所有已缓存的日期,为目标商品重新获取价格并覆盖到缓存中
160
+ * 指定商品的报价单价格变更时,清除价格缓存
161
+ * 后续查询会走完整的 formatter 管道重建缓存
162
162
  */
163
163
  updateProductPriceByIds(ids: number[]): Promise<void>;
164
164
  /**
@@ -202,15 +202,14 @@ export declare class ProductsModule extends BaseModule implements Module {
202
202
  *
203
203
  * product 模块:
204
204
  * - operation === 'delete' → 本地删除
205
- * - change_types 包含 price → SSE 增量拉取 + 刷新报价单价格缓存
205
+ * - change_types 包含 price → SSE 增量拉取
206
206
  * - 有 body → body 完整数据直接覆盖本地
207
-
208
207
  *
209
208
  * product_collection / product_category / product_quotation:
210
209
  * - 按 relation_product_ids SSE 拉取受影响商品
211
- * - product_quotation 额外刷新报价单价格缓存
212
210
  *
213
- * 处理完成后 emit onProductsSyncCompleted 通知 Server 层
211
+ * 处理完成后清除价格缓存并 emit onProductsSyncCompleted
212
+ * Server 层监听该事件后重新查询,走完整的 formatter 管道重建缓存
214
213
  */
215
214
  private processProductSyncMessages;
216
215
  /**
@@ -221,7 +220,8 @@ export declare class ProductsModule extends BaseModule implements Module {
221
220
  /**
222
221
  * 将 body 完整数据直接覆盖到本地 store(不调用报价单接口)
223
222
  * 已存在的 → 直接替换;不存在的 → 追加
224
- * 同时更新 Map 缓存、IndexDB,清空价格缓存,触发 onProductsChanged
223
+ * 同时更新 Map 缓存、IndexDB,触发 onProductsChanged
224
+ * 价格缓存由 processProductSyncMessages 末尾统一清除
225
225
  */
226
226
  private applyBodyUpdatesToStore;
227
227
  /**
@@ -230,16 +230,6 @@ export declare class ProductsModule extends BaseModule implements Module {
230
230
  * 同时更新 store.map、IndexDB,触发 onProductsChanged
231
231
  */
232
232
  private mergeProductsToStore;
233
- /**
234
- * 增量更新价格缓存中变更的商品
235
- * 对每个已缓存的日期 key:替换/追加最新商品数据,重新拉取这些 ID 的价格并应用
236
- */
237
- private updatePriceCacheForProducts;
238
- /**
239
- * 全量重新拉取报价单价格并重建价格缓存
240
- * 遍历当前已缓存的所有日期 key,对每个日期重新调用 loadProductsPrice
241
- */
242
- private refreshAllPriceCache;
243
233
  /**
244
234
  * 静默全量刷新:后台重新拉取全量 SSE 数据并更新本地
245
235
  * 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
@@ -1013,76 +1013,26 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1013
1013
  return refreshProducts;
1014
1014
  }()
1015
1015
  /**
1016
- * 局部更新指定商品的报价单价格
1017
- * 遍历所有已缓存的日期,为目标商品重新获取价格并覆盖到缓存中
1016
+ * 指定商品的报价单价格变更时,清除价格缓存
1017
+ * 后续查询会走完整的 formatter 管道重建缓存
1018
1018
  */
1019
1019
  )
1020
1020
  }, {
1021
1021
  key: "updateProductPriceByIds",
1022
1022
  value: (function () {
1023
1023
  var _updateProductPriceByIds = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(ids) {
1024
- var _iterator4, _step4, _step4$value, dateKey, cachedProducts, priceData, updatedProducts, errorMessage;
1025
1024
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1026
1025
  while (1) switch (_context13.prev = _context13.next) {
1027
1026
  case 0:
1028
- this.logInfo('updateProductPriceByIds', {
1027
+ this.logInfo('updateProductPriceByIds: 清除价格缓存', {
1029
1028
  ids: ids
1030
1029
  });
1031
- _iterator4 = _createForOfIteratorHelper(this.productsPriceCache.entries());
1032
- _context13.prev = 2;
1033
- _iterator4.s();
1034
- case 4:
1035
- if ((_step4 = _iterator4.n()).done) {
1036
- _context13.next = 19;
1037
- break;
1038
- }
1039
- _step4$value = _slicedToArray(_step4.value, 2), dateKey = _step4$value[0], cachedProducts = _step4$value[1];
1040
- _context13.prev = 6;
1041
- _context13.next = 9;
1042
- return this.loadProductsPrice({
1043
- ids: ids,
1044
- schedule_date: dateKey
1045
- });
1046
- case 9:
1047
- priceData = _context13.sent;
1048
- if (priceData && priceData.length > 0) {
1049
- updatedProducts = applyPriceDataToProducts(cachedProducts, priceData);
1050
- this.productsPriceCache.set(dateKey, updatedProducts);
1051
- this.logInfo('updateProductPriceByIds: 缓存已更新', {
1052
- dateKey: dateKey,
1053
- priceDataCount: priceData.length
1054
- });
1055
- }
1056
- _context13.next = 17;
1057
- break;
1058
- case 13:
1059
- _context13.prev = 13;
1060
- _context13.t0 = _context13["catch"](6);
1061
- errorMessage = _context13.t0 instanceof Error ? _context13.t0.message : String(_context13.t0);
1062
- this.logError('updateProductPriceByIds: 失败', {
1063
- dateKey: dateKey,
1064
- ids: ids,
1065
- error: errorMessage
1066
- });
1067
- case 17:
1068
- _context13.next = 4;
1069
- break;
1070
- case 19:
1071
- _context13.next = 24;
1072
- break;
1073
- case 21:
1074
- _context13.prev = 21;
1075
- _context13.t1 = _context13["catch"](2);
1076
- _iterator4.e(_context13.t1);
1077
- case 24:
1078
- _context13.prev = 24;
1079
- _iterator4.f();
1080
- return _context13.finish(24);
1081
- case 27:
1030
+ this.clearPriceCache();
1031
+ case 2:
1082
1032
  case "end":
1083
1033
  return _context13.stop();
1084
1034
  }
1085
- }, _callee13, this, [[2, 21, 24, 27], [6, 13]]);
1035
+ }, _callee13, this);
1086
1036
  }));
1087
1037
  function updateProductPriceByIds(_x14) {
1088
1038
  return _updateProductPriceByIds.apply(this, arguments);
@@ -1267,17 +1217,17 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1267
1217
  value: function syncProductsMap() {
1268
1218
  var t0 = performance.now();
1269
1219
  this.store.map.clear();
1270
- var _iterator5 = _createForOfIteratorHelper(this.store.list),
1271
- _step5;
1220
+ var _iterator4 = _createForOfIteratorHelper(this.store.list),
1221
+ _step4;
1272
1222
  try {
1273
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1274
- var product = _step5.value;
1223
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1224
+ var product = _step4.value;
1275
1225
  this.store.map.set(product.id, product);
1276
1226
  }
1277
1227
  } catch (err) {
1278
- _iterator5.e(err);
1228
+ _iterator4.e(err);
1279
1229
  } finally {
1280
- _iterator5.f();
1230
+ _iterator4.f();
1281
1231
  }
1282
1232
  perfMark('syncProductsMap', performance.now() - t0, {
1283
1233
  count: this.store.map.size
@@ -1472,20 +1422,20 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1472
1422
  *
1473
1423
  * product 模块:
1474
1424
  * - operation === 'delete' → 本地删除
1475
- * - change_types 包含 price → SSE 增量拉取 + 刷新报价单价格缓存
1425
+ * - change_types 包含 price → SSE 增量拉取
1476
1426
  * - 有 body → body 完整数据直接覆盖本地
1477
- *
1427
+ *
1478
1428
  * product_collection / product_category / product_quotation:
1479
1429
  * - 按 relation_product_ids SSE 拉取受影响商品
1480
- * - product_quotation 额外刷新报价单价格缓存
1481
1430
  *
1482
- * 处理完成后 emit onProductsSyncCompleted 通知 Server 层
1431
+ * 处理完成后清除价格缓存并 emit onProductsSyncCompleted
1432
+ * Server 层监听该事件后重新查询,走完整的 formatter 管道重建缓存
1483
1433
  */
1484
1434
  }, {
1485
1435
  key: "processProductSyncMessages",
1486
1436
  value: (function () {
1487
1437
  var _processProductSyncMessages = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
1488
- var messages, deleteIds, bodyUpdates, sseRefreshIds, priceRefreshIds, _iterator6, _step6, msg, channelKey, _msg$change_types, _msg$ids2, _msg$ids, ids, _msg$relation_product, bodyId, _msg$relation_product2, uniqueDeleteIds, uniqueSSEIds, uniquePriceIds, freshProducts, sseHandledSet, remainingPriceIds;
1438
+ var messages, deleteIds, bodyUpdates, sseRefreshIds, _iterator5, _step5, msg, channelKey, _msg$change_types, _msg$ids2, _msg$ids, ids, _msg$relation_product, bodyId, _msg$relation_product2, uniqueDeleteIds, uniqueSSEIds, freshProducts;
1489
1439
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1490
1440
  while (1) switch (_context18.prev = _context18.next) {
1491
1441
  case 0:
@@ -1503,39 +1453,37 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1503
1453
  deleteIds = [];
1504
1454
  bodyUpdates = new Map();
1505
1455
  sseRefreshIds = [];
1506
- priceRefreshIds = [];
1507
- _iterator6 = _createForOfIteratorHelper(messages);
1508
- _context18.prev = 10;
1509
- _iterator6.s();
1510
- case 12:
1511
- if ((_step6 = _iterator6.n()).done) {
1512
- _context18.next = 35;
1456
+ _iterator5 = _createForOfIteratorHelper(messages);
1457
+ _context18.prev = 9;
1458
+ _iterator5.s();
1459
+ case 11:
1460
+ if ((_step5 = _iterator5.n()).done) {
1461
+ _context18.next = 33;
1513
1462
  break;
1514
1463
  }
1515
- msg = _step6.value;
1464
+ msg = _step5.value;
1516
1465
  channelKey = msg._channelKey || msg.module || 'product';
1517
1466
  if (!(channelKey === 'product')) {
1518
- _context18.next = 32;
1467
+ _context18.next = 30;
1519
1468
  break;
1520
1469
  }
1521
1470
  if (!(msg.operation === 'delete' || msg.action === 'delete')) {
1522
- _context18.next = 19;
1471
+ _context18.next = 18;
1523
1472
  break;
1524
1473
  }
1525
1474
  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);
1526
- return _context18.abrupt("continue", 33);
1527
- case 19:
1475
+ return _context18.abrupt("continue", 31);
1476
+ case 18:
1528
1477
  if (!((_msg$change_types = msg.change_types) !== null && _msg$change_types !== void 0 && _msg$change_types.includes('price'))) {
1529
- _context18.next = 24;
1478
+ _context18.next = 22;
1530
1479
  break;
1531
1480
  }
1532
1481
  ids = msg.ids || (msg.id ? [msg.id] : []);
1533
1482
  sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(ids));
1534
- priceRefreshIds.push.apply(priceRefreshIds, _toConsumableArray(ids));
1535
- return _context18.abrupt("continue", 33);
1536
- case 24:
1483
+ return _context18.abrupt("continue", 31);
1484
+ case 22:
1537
1485
  if (!msg.body) {
1538
- _context18.next = 29;
1486
+ _context18.next = 27;
1539
1487
  break;
1540
1488
  }
1541
1489
  bodyId = msg.body.id || msg.id;
@@ -1543,115 +1491,96 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1543
1491
  if ((_msg$relation_product = msg.relation_product_ids) !== null && _msg$relation_product !== void 0 && _msg$relation_product.length) {
1544
1492
  sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_product_ids));
1545
1493
  }
1546
- return _context18.abrupt("continue", 33);
1547
- case 29:
1494
+ return _context18.abrupt("continue", 31);
1495
+ case 27:
1548
1496
  // 5. 其他情况(有 ids 无 body 无 change_types)→ SSE 拉取
1549
1497
  if ((_msg$ids2 = msg.ids) !== null && _msg$ids2 !== void 0 && _msg$ids2.length) {
1550
1498
  sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.ids));
1551
1499
  } else if (msg.id) {
1552
1500
  sseRefreshIds.push(msg.id);
1553
1501
  }
1554
- _context18.next = 33;
1502
+ _context18.next = 31;
1555
1503
  break;
1556
- case 32:
1504
+ case 30:
1557
1505
  if (['product_collection', 'product_category', 'product_quotation'].includes(channelKey)) {
1558
1506
  if ((_msg$relation_product2 = msg.relation_product_ids) !== null && _msg$relation_product2 !== void 0 && _msg$relation_product2.length) {
1559
1507
  sseRefreshIds.push.apply(sseRefreshIds, _toConsumableArray(msg.relation_product_ids));
1560
- if (channelKey === 'product_quotation') {
1561
- this.clearPriceCache();
1562
- priceRefreshIds.push.apply(priceRefreshIds, _toConsumableArray(msg.relation_product_ids));
1563
- }
1564
1508
  }
1565
1509
  }
1510
+ case 31:
1511
+ _context18.next = 11;
1512
+ break;
1566
1513
  case 33:
1567
- _context18.next = 12;
1514
+ _context18.next = 38;
1568
1515
  break;
1569
1516
  case 35:
1570
- _context18.next = 40;
1571
- break;
1572
- case 37:
1573
- _context18.prev = 37;
1574
- _context18.t0 = _context18["catch"](10);
1575
- _iterator6.e(_context18.t0);
1576
- case 40:
1577
- _context18.prev = 40;
1578
- _iterator6.f();
1579
- return _context18.finish(40);
1580
- case 43:
1517
+ _context18.prev = 35;
1518
+ _context18.t0 = _context18["catch"](9);
1519
+ _iterator5.e(_context18.t0);
1520
+ case 38:
1521
+ _context18.prev = 38;
1522
+ _iterator5.f();
1523
+ return _context18.finish(38);
1524
+ case 41:
1581
1525
  uniqueDeleteIds = _toConsumableArray(new Set(deleteIds));
1582
- uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds));
1583
- uniquePriceIds = _toConsumableArray(new Set(priceRefreshIds)); // 1. 处理删除
1526
+ uniqueSSEIds = _toConsumableArray(new Set(sseRefreshIds)); // 1. 处理删除
1584
1527
  if (!(uniqueDeleteIds.length > 0)) {
1585
- _context18.next = 49;
1528
+ _context18.next = 46;
1586
1529
  break;
1587
1530
  }
1588
- _context18.next = 49;
1531
+ _context18.next = 46;
1589
1532
  return this.removeProductsByIds(uniqueDeleteIds);
1590
- case 49:
1533
+ case 46:
1591
1534
  if (!(bodyUpdates.size > 0)) {
1592
- _context18.next = 52;
1535
+ _context18.next = 49;
1593
1536
  break;
1594
1537
  }
1595
- _context18.next = 52;
1538
+ _context18.next = 49;
1596
1539
  return this.applyBodyUpdatesToStore(bodyUpdates);
1597
- case 52:
1540
+ case 49:
1598
1541
  if (!(uniqueSSEIds.length > 0)) {
1599
- _context18.next = 62;
1542
+ _context18.next = 57;
1600
1543
  break;
1601
1544
  }
1602
- _context18.next = 55;
1545
+ _context18.next = 52;
1603
1546
  return this.fetchProductsBySSE(uniqueSSEIds);
1604
- case 55:
1547
+ case 52:
1605
1548
  freshProducts = _context18.sent;
1606
1549
  if (!(freshProducts.length > 0)) {
1607
- _context18.next = 61;
1550
+ _context18.next = 56;
1608
1551
  break;
1609
1552
  }
1610
- _context18.next = 59;
1553
+ _context18.next = 56;
1611
1554
  return this.mergeProductsToStore(freshProducts);
1612
- case 59:
1613
- _context18.next = 61;
1614
- return this.updatePriceCacheForProducts(freshProducts);
1615
- case 61:
1555
+ case 56:
1616
1556
  this.logInfo('processProductSyncMessages: SSE 增量更新完成', {
1617
1557
  requestedCount: uniqueSSEIds.length,
1618
1558
  receivedCount: freshProducts.length
1619
1559
  });
1620
- case 62:
1621
- // 4. 处理报价单价格刷新(排除已被第3步 SSE 处理过的 id,避免重复请求)
1622
- sseHandledSet = new Set(uniqueSSEIds);
1623
- remainingPriceIds = uniquePriceIds.filter(function (id) {
1624
- return !sseHandledSet.has(id);
1625
- });
1626
- if (!(remainingPriceIds.length > 0)) {
1627
- _context18.next = 67;
1628
- break;
1629
- }
1630
- _context18.next = 67;
1631
- return this.updateProductPriceByIds(remainingPriceIds);
1632
- case 67:
1560
+ case 57:
1633
1561
  this.logInfo('processProductSyncMessages: 处理完成', {
1634
1562
  deleteCount: uniqueDeleteIds.length,
1635
1563
  bodyUpdateCount: bodyUpdates.size,
1636
- sseRefreshCount: uniqueSSEIds.length,
1637
- priceRefreshCount: uniquePriceIds.length
1564
+ sseRefreshCount: uniqueSSEIds.length
1638
1565
  });
1639
1566
 
1640
1567
  // 如果都没有变更,则不触发 onProductsSyncCompleted
1641
- if (!(uniqueDeleteIds.length === 0 && bodyUpdates.size === 0 && uniqueSSEIds.length === 0 && uniquePriceIds.length === 0)) {
1642
- _context18.next = 71;
1568
+ if (!(uniqueDeleteIds.length === 0 && bodyUpdates.size === 0 && uniqueSSEIds.length === 0)) {
1569
+ _context18.next = 61;
1643
1570
  break;
1644
1571
  }
1645
1572
  this.logInfo('processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted');
1646
1573
  return _context18.abrupt("return");
1647
- case 71:
1648
- _context18.next = 73;
1574
+ case 61:
1575
+ // 清除价格缓存,让后续查询走完整的 formatter 管道重建(含 detailValueFormatter)
1576
+ this.clearPriceCache();
1577
+ _context18.next = 64;
1649
1578
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
1650
- case 73:
1579
+ case 64:
1651
1580
  case "end":
1652
1581
  return _context18.stop();
1653
1582
  }
1654
- }, _callee18, this, [[10, 37, 40, 43]]);
1583
+ }, _callee18, this, [[9, 35, 38, 41]]);
1655
1584
  }));
1656
1585
  function processProductSyncMessages() {
1657
1586
  return _processProductSyncMessages.apply(this, arguments);
@@ -1728,14 +1657,15 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1728
1657
  /**
1729
1658
  * 将 body 完整数据直接覆盖到本地 store(不调用报价单接口)
1730
1659
  * 已存在的 → 直接替换;不存在的 → 追加
1731
- * 同时更新 Map 缓存、IndexDB,清空价格缓存,触发 onProductsChanged
1660
+ * 同时更新 Map 缓存、IndexDB,触发 onProductsChanged
1661
+ * 价格缓存由 processProductSyncMessages 末尾统一清除
1732
1662
  */
1733
1663
  )
1734
1664
  }, {
1735
1665
  key: "applyBodyUpdatesToStore",
1736
1666
  value: (function () {
1737
1667
  var _applyBodyUpdatesToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(bodyUpdates) {
1738
- var updatedCount, newCount, appliedIds, _iterator7, _step7, _step7$value, id, body;
1668
+ var updatedCount, newCount, appliedIds, _iterator6, _step6, _step6$value, id, body;
1739
1669
  return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1740
1670
  while (1) switch (_context20.prev = _context20.next) {
1741
1671
  case 0:
@@ -1753,34 +1683,31 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1753
1683
  }
1754
1684
  return p;
1755
1685
  });
1756
- _iterator7 = _createForOfIteratorHelper(bodyUpdates);
1686
+ _iterator6 = _createForOfIteratorHelper(bodyUpdates);
1757
1687
  try {
1758
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1759
- _step7$value = _slicedToArray(_step7.value, 2), id = _step7$value[0], body = _step7$value[1];
1688
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1689
+ _step6$value = _slicedToArray(_step6.value, 2), id = _step6$value[0], body = _step6$value[1];
1760
1690
  if (!appliedIds.has(id)) {
1761
1691
  this.store.list.push(body);
1762
1692
  newCount++;
1763
1693
  }
1764
1694
  }
1765
1695
  } catch (err) {
1766
- _iterator7.e(err);
1696
+ _iterator6.e(err);
1767
1697
  } finally {
1768
- _iterator7.f();
1698
+ _iterator6.f();
1769
1699
  }
1770
1700
  this.syncProductsMap();
1771
1701
  _context20.next = 10;
1772
1702
  return this.saveProductsToIndexDB(this.store.list);
1773
1703
  case 10:
1774
- _context20.next = 12;
1775
- return this.updatePriceCacheForProducts(_toConsumableArray(bodyUpdates.values()));
1776
- case 12:
1777
1704
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
1778
1705
  this.logInfo('applyBodyUpdatesToStore: 完成', {
1779
1706
  updatedCount: updatedCount,
1780
1707
  newCount: newCount,
1781
1708
  totalCount: this.store.list.length
1782
1709
  });
1783
- case 14:
1710
+ case 12:
1784
1711
  case "end":
1785
1712
  return _context20.stop();
1786
1713
  }
@@ -1801,21 +1728,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1801
1728
  key: "mergeProductsToStore",
1802
1729
  value: (function () {
1803
1730
  var _mergeProductsToStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(freshProducts) {
1804
- var freshMap, _iterator8, _step8, p, updatedList, newCount, _iterator9, _step9, _p, updatedCount;
1731
+ var freshMap, _iterator7, _step7, p, updatedList, newCount, _iterator8, _step8, _p, updatedCount;
1805
1732
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1806
1733
  while (1) switch (_context21.prev = _context21.next) {
1807
1734
  case 0:
1808
1735
  freshMap = new Map();
1809
- _iterator8 = _createForOfIteratorHelper(freshProducts);
1736
+ _iterator7 = _createForOfIteratorHelper(freshProducts);
1810
1737
  try {
1811
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1812
- p = _step8.value;
1738
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1739
+ p = _step7.value;
1813
1740
  freshMap.set(p.id, p);
1814
1741
  }
1815
1742
  } catch (err) {
1816
- _iterator8.e(err);
1743
+ _iterator7.e(err);
1817
1744
  } finally {
1818
- _iterator8.f();
1745
+ _iterator7.f();
1819
1746
  }
1820
1747
  updatedList = this.store.list.map(function (p) {
1821
1748
  if (freshMap.has(p.id)) {
@@ -1826,16 +1753,16 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1826
1753
  return p;
1827
1754
  }); // freshMap 中剩余的是新商品(create 场景)
1828
1755
  newCount = freshMap.size;
1829
- _iterator9 = _createForOfIteratorHelper(freshMap.values());
1756
+ _iterator8 = _createForOfIteratorHelper(freshMap.values());
1830
1757
  try {
1831
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
1832
- _p = _step9.value;
1758
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
1759
+ _p = _step8.value;
1833
1760
  updatedList.push(_p);
1834
1761
  }
1835
1762
  } catch (err) {
1836
- _iterator9.e(err);
1763
+ _iterator8.e(err);
1837
1764
  } finally {
1838
- _iterator9.f();
1765
+ _iterator8.f();
1839
1766
  }
1840
1767
  updatedCount = freshProducts.length - newCount;
1841
1768
  this.store.list = updatedList;
@@ -1860,208 +1787,6 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
1860
1787
  }
1861
1788
  return mergeProductsToStore;
1862
1789
  }()
1863
- /**
1864
- * 增量更新价格缓存中变更的商品
1865
- * 对每个已缓存的日期 key:替换/追加最新商品数据,重新拉取这些 ID 的价格并应用
1866
- */
1867
- )
1868
- }, {
1869
- key: "updatePriceCacheForProducts",
1870
- value: (function () {
1871
- var _updatePriceCacheForProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(freshProducts) {
1872
- var freshIds, freshMap, _iterator10, _step10, p, _iterator11, _step11, _step11$value, dateKey, cachedProducts, updatedList, existingIds, _iterator12, _step12, _p2, priceData, result, errorMessage;
1873
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1874
- while (1) switch (_context22.prev = _context22.next) {
1875
- case 0:
1876
- if (!(this.productsPriceCache.size === 0)) {
1877
- _context22.next = 2;
1878
- break;
1879
- }
1880
- return _context22.abrupt("return");
1881
- case 2:
1882
- freshIds = freshProducts.map(function (p) {
1883
- return p.id;
1884
- });
1885
- freshMap = new Map();
1886
- _iterator10 = _createForOfIteratorHelper(freshProducts);
1887
- try {
1888
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
1889
- p = _step10.value;
1890
- freshMap.set(p.id, p);
1891
- }
1892
- } catch (err) {
1893
- _iterator10.e(err);
1894
- } finally {
1895
- _iterator10.f();
1896
- }
1897
- this.logInfo('updatePriceCacheForProducts: 开始', {
1898
- freshIds: freshIds,
1899
- cachedDateCount: this.productsPriceCache.size
1900
- });
1901
- _iterator11 = _createForOfIteratorHelper(this.productsPriceCache.entries());
1902
- _context22.prev = 8;
1903
- _iterator11.s();
1904
- case 10:
1905
- if ((_step11 = _iterator11.n()).done) {
1906
- _context22.next = 31;
1907
- break;
1908
- }
1909
- _step11$value = _slicedToArray(_step11.value, 2), dateKey = _step11$value[0], cachedProducts = _step11$value[1];
1910
- _context22.prev = 12;
1911
- // 1. 替换已有商品 / 收集新增商品
1912
- updatedList = cachedProducts.map(function (p) {
1913
- var fresh = freshMap.get(p.id);
1914
- return fresh ? _objectSpread({}, fresh) : p;
1915
- }); // 追加新增商品(缓存中不存在的 ID)
1916
- existingIds = new Set(cachedProducts.map(function (p) {
1917
- return p.id;
1918
- }));
1919
- _iterator12 = _createForOfIteratorHelper(freshProducts);
1920
- try {
1921
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
1922
- _p2 = _step12.value;
1923
- if (!existingIds.has(_p2.id)) {
1924
- updatedList.push(_objectSpread({}, _p2));
1925
- }
1926
- }
1927
-
1928
- // 2. 拉取这些 ID 的最新价格并应用
1929
- } catch (err) {
1930
- _iterator12.e(err);
1931
- } finally {
1932
- _iterator12.f();
1933
- }
1934
- _context22.next = 19;
1935
- return this.loadProductsPrice({
1936
- ids: freshIds,
1937
- schedule_date: dateKey
1938
- });
1939
- case 19:
1940
- priceData = _context22.sent;
1941
- result = priceData && priceData.length > 0 ? applyPriceDataToProducts(updatedList, priceData) : updatedList;
1942
- this.productsPriceCache.set(dateKey, result);
1943
- this.logInfo('updatePriceCacheForProducts: 日期缓存已更新', {
1944
- dateKey: dateKey,
1945
- updatedIds: freshIds
1946
- });
1947
- _context22.next = 29;
1948
- break;
1949
- case 25:
1950
- _context22.prev = 25;
1951
- _context22.t0 = _context22["catch"](12);
1952
- errorMessage = _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0);
1953
- this.logError('updatePriceCacheForProducts: 失败', {
1954
- dateKey: dateKey,
1955
- error: errorMessage
1956
- });
1957
- case 29:
1958
- _context22.next = 10;
1959
- break;
1960
- case 31:
1961
- _context22.next = 36;
1962
- break;
1963
- case 33:
1964
- _context22.prev = 33;
1965
- _context22.t1 = _context22["catch"](8);
1966
- _iterator11.e(_context22.t1);
1967
- case 36:
1968
- _context22.prev = 36;
1969
- _iterator11.f();
1970
- return _context22.finish(36);
1971
- case 39:
1972
- case "end":
1973
- return _context22.stop();
1974
- }
1975
- }, _callee22, this, [[8, 33, 36, 39], [12, 25]]);
1976
- }));
1977
- function updatePriceCacheForProducts(_x19) {
1978
- return _updatePriceCacheForProducts.apply(this, arguments);
1979
- }
1980
- return updatePriceCacheForProducts;
1981
- }()
1982
- /**
1983
- * 全量重新拉取报价单价格并重建价格缓存
1984
- * 遍历当前已缓存的所有日期 key,对每个日期重新调用 loadProductsPrice
1985
- */
1986
- )
1987
- }, {
1988
- key: "refreshAllPriceCache",
1989
- value: (function () {
1990
- var _refreshAllPriceCache = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
1991
- var allProducts, ids, dateKeys, _i, _dateKeys, dateKey, priceData, updatedProducts, errorMessage;
1992
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
1993
- while (1) switch (_context23.prev = _context23.next) {
1994
- case 0:
1995
- allProducts = this.getProductsRef();
1996
- if (!(allProducts.length === 0)) {
1997
- _context23.next = 3;
1998
- break;
1999
- }
2000
- return _context23.abrupt("return");
2001
- case 3:
2002
- ids = allProducts.map(function (p) {
2003
- return p.id;
2004
- }); // 先快照当前已缓存的日期 key,再清空缓存
2005
- dateKeys = Array.from(this.productsPriceCache.keys());
2006
- this.clearPriceCache();
2007
- if (!(dateKeys.length === 0)) {
2008
- _context23.next = 9;
2009
- break;
2010
- }
2011
- this.logInfo('refreshAllPriceCache: 无已缓存日期,跳过');
2012
- return _context23.abrupt("return");
2013
- case 9:
2014
- this.logInfo('refreshAllPriceCache: 开始重新拉取', {
2015
- dateKeys: dateKeys,
2016
- productCount: ids.length
2017
- });
2018
- _i = 0, _dateKeys = dateKeys;
2019
- case 11:
2020
- if (!(_i < _dateKeys.length)) {
2021
- _context23.next = 28;
2022
- break;
2023
- }
2024
- dateKey = _dateKeys[_i];
2025
- _context23.prev = 13;
2026
- _context23.next = 16;
2027
- return this.loadProductsPrice({
2028
- ids: ids,
2029
- schedule_date: dateKey
2030
- });
2031
- case 16:
2032
- priceData = _context23.sent;
2033
- if (priceData && priceData.length > 0) {
2034
- updatedProducts = applyPriceDataToProducts(allProducts, priceData);
2035
- this.productsPriceCache.set(dateKey, updatedProducts);
2036
- }
2037
- this.logInfo('refreshAllPriceCache: 日期缓存已更新', {
2038
- dateKey: dateKey
2039
- });
2040
- _context23.next = 25;
2041
- break;
2042
- case 21:
2043
- _context23.prev = 21;
2044
- _context23.t0 = _context23["catch"](13);
2045
- errorMessage = _context23.t0 instanceof Error ? _context23.t0.message : String(_context23.t0);
2046
- this.logError('refreshAllPriceCache: 失败', {
2047
- dateKey: dateKey,
2048
- error: errorMessage
2049
- });
2050
- case 25:
2051
- _i++;
2052
- _context23.next = 11;
2053
- break;
2054
- case 28:
2055
- case "end":
2056
- return _context23.stop();
2057
- }
2058
- }, _callee23, this, [[13, 21]]);
2059
- }));
2060
- function refreshAllPriceCache() {
2061
- return _refreshAllPriceCache.apply(this, arguments);
2062
- }
2063
- return refreshAllPriceCache;
2064
- }()
2065
1790
  /**
2066
1791
  * 静默全量刷新:后台重新拉取全量 SSE 数据并更新本地
2067
1792
  * 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
@@ -2071,34 +1796,34 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2071
1796
  }, {
2072
1797
  key: "silentRefresh",
2073
1798
  value: (function () {
2074
- var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
1799
+ var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
2075
1800
  var t0, products, errorMessage;
2076
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2077
- while (1) switch (_context24.prev = _context24.next) {
1801
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
1802
+ while (1) switch (_context22.prev = _context22.next) {
2078
1803
  case 0:
2079
1804
  t0 = performance.now();
2080
1805
  this.logInfo('silentRefresh 开始');
2081
- _context24.prev = 2;
2082
- _context24.next = 5;
1806
+ _context22.prev = 2;
1807
+ _context22.next = 5;
2083
1808
  return this.loadProductsByServer();
2084
1809
  case 5:
2085
- products = _context24.sent;
1810
+ products = _context22.sent;
2086
1811
  if (!(products && products.length > 0)) {
2087
- _context24.next = 16;
1812
+ _context22.next = 16;
2088
1813
  break;
2089
1814
  }
2090
1815
  this.store.list = products;
2091
1816
  this.syncProductsMap();
2092
1817
  this.clearPriceCache();
2093
1818
  this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
2094
- _context24.next = 13;
1819
+ _context22.next = 13;
2095
1820
  return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
2096
1821
  case 13:
2097
1822
  this.logInfo('silentRefresh 完成', {
2098
1823
  productCount: products.length,
2099
1824
  duration: "".concat(Math.round(performance.now() - t0), "ms")
2100
1825
  });
2101
- _context24.next = 17;
1826
+ _context22.next = 17;
2102
1827
  break;
2103
1828
  case 16:
2104
1829
  this.logWarning('silentRefresh: 服务器未返回数据');
@@ -2106,21 +1831,21 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
2106
1831
  perfMark('silentRefresh', performance.now() - t0, {
2107
1832
  count: this.store.list.length
2108
1833
  });
2109
- return _context24.abrupt("return", this.store.list);
1834
+ return _context22.abrupt("return", this.store.list);
2110
1835
  case 21:
2111
- _context24.prev = 21;
2112
- _context24.t0 = _context24["catch"](2);
2113
- errorMessage = _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0);
1836
+ _context22.prev = 21;
1837
+ _context22.t0 = _context22["catch"](2);
1838
+ errorMessage = _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0);
2114
1839
  this.logError('silentRefresh 失败', {
2115
1840
  duration: "".concat(Math.round(performance.now() - t0), "ms"),
2116
1841
  error: errorMessage
2117
1842
  });
2118
- return _context24.abrupt("return", this.store.list);
1843
+ return _context22.abrupt("return", this.store.list);
2119
1844
  case 26:
2120
1845
  case "end":
2121
- return _context24.stop();
1846
+ return _context22.stop();
2122
1847
  }
2123
- }, _callee24, this, [[2, 21]]);
1848
+ }, _callee22, this, [[2, 21]]);
2124
1849
  }));
2125
1850
  function silentRefresh() {
2126
1851
  return _silentRefresh.apply(this, arguments);
@@ -701,6 +701,13 @@ var Server = class {
701
701
  before: allProductsWithPrice.length,
702
702
  after: filteredProducts.length
703
703
  });
704
+ const tStatus = performance.now();
705
+ const beforeStatusCount = filteredProducts.length;
706
+ filteredProducts = filteredProducts.filter((p) => ((p == null ? void 0 : p.status) || "published") === "published");
707
+ (0, import_product.perfMark)("computeQuery.filterByStatus", performance.now() - tStatus, {
708
+ before: beforeStatusCount,
709
+ after: filteredProducts.length
710
+ });
704
711
  const tSort = performance.now();
705
712
  filteredProducts = filteredProducts.sort((a, b) => {
706
713
  const sortDiff = Number(b.sort) - Number(a.sort);
@@ -157,8 +157,8 @@ export declare class ProductsModule extends BaseModule implements Module {
157
157
  */
158
158
  refreshProducts(): Promise<ProductData[]>;
159
159
  /**
160
- * 局部更新指定商品的报价单价格
161
- * 遍历所有已缓存的日期,为目标商品重新获取价格并覆盖到缓存中
160
+ * 指定商品的报价单价格变更时,清除价格缓存
161
+ * 后续查询会走完整的 formatter 管道重建缓存
162
162
  */
163
163
  updateProductPriceByIds(ids: number[]): Promise<void>;
164
164
  /**
@@ -202,15 +202,14 @@ export declare class ProductsModule extends BaseModule implements Module {
202
202
  *
203
203
  * product 模块:
204
204
  * - operation === 'delete' → 本地删除
205
- * - change_types 包含 price → SSE 增量拉取 + 刷新报价单价格缓存
205
+ * - change_types 包含 price → SSE 增量拉取
206
206
  * - 有 body → body 完整数据直接覆盖本地
207
-
208
207
  *
209
208
  * product_collection / product_category / product_quotation:
210
209
  * - 按 relation_product_ids SSE 拉取受影响商品
211
- * - product_quotation 额外刷新报价单价格缓存
212
210
  *
213
- * 处理完成后 emit onProductsSyncCompleted 通知 Server 层
211
+ * 处理完成后清除价格缓存并 emit onProductsSyncCompleted
212
+ * Server 层监听该事件后重新查询,走完整的 formatter 管道重建缓存
214
213
  */
215
214
  private processProductSyncMessages;
216
215
  /**
@@ -221,7 +220,8 @@ export declare class ProductsModule extends BaseModule implements Module {
221
220
  /**
222
221
  * 将 body 完整数据直接覆盖到本地 store(不调用报价单接口)
223
222
  * 已存在的 → 直接替换;不存在的 → 追加
224
- * 同时更新 Map 缓存、IndexDB,清空价格缓存,触发 onProductsChanged
223
+ * 同时更新 Map 缓存、IndexDB,触发 onProductsChanged
224
+ * 价格缓存由 processProductSyncMessages 末尾统一清除
225
225
  */
226
226
  private applyBodyUpdatesToStore;
227
227
  /**
@@ -230,16 +230,6 @@ export declare class ProductsModule extends BaseModule implements Module {
230
230
  * 同时更新 store.map、IndexDB,触发 onProductsChanged
231
231
  */
232
232
  private mergeProductsToStore;
233
- /**
234
- * 增量更新价格缓存中变更的商品
235
- * 对每个已缓存的日期 key:替换/追加最新商品数据,重新拉取这些 ID 的价格并应用
236
- */
237
- private updatePriceCacheForProducts;
238
- /**
239
- * 全量重新拉取报价单价格并重建价格缓存
240
- * 遍历当前已缓存的所有日期 key,对每个日期重新调用 loadProductsPrice
241
- */
242
- private refreshAllPriceCache;
243
233
  /**
244
234
  * 静默全量刷新:后台重新拉取全量 SSE 数据并更新本地
245
235
  * 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
@@ -605,27 +605,12 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
605
605
  return this.store.list;
606
606
  }
607
607
  /**
608
- * 局部更新指定商品的报价单价格
609
- * 遍历所有已缓存的日期,为目标商品重新获取价格并覆盖到缓存中
608
+ * 指定商品的报价单价格变更时,清除价格缓存
609
+ * 后续查询会走完整的 formatter 管道重建缓存
610
610
  */
611
611
  async updateProductPriceByIds(ids) {
612
- this.logInfo("updateProductPriceByIds", { ids });
613
- for (const [dateKey, cachedProducts] of this.productsPriceCache.entries()) {
614
- try {
615
- const priceData = await this.loadProductsPrice({
616
- ids,
617
- schedule_date: dateKey
618
- });
619
- if (priceData && priceData.length > 0) {
620
- const updatedProducts = (0, import_product.applyPriceDataToProducts)(cachedProducts, priceData);
621
- this.productsPriceCache.set(dateKey, updatedProducts);
622
- this.logInfo("updateProductPriceByIds: 缓存已更新", { dateKey, priceDataCount: priceData.length });
623
- }
624
- } catch (error) {
625
- const errorMessage = error instanceof Error ? error.message : String(error);
626
- this.logError("updateProductPriceByIds: 失败", { dateKey, ids, error: errorMessage });
627
- }
628
- }
612
+ this.logInfo("updateProductPriceByIds: 清除价格缓存", { ids });
613
+ this.clearPriceCache();
629
614
  }
630
615
  /**
631
616
  * 清空缓存
@@ -849,20 +834,19 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
849
834
  this.logInfo("setupProductSync: pubsub 订阅已建立");
850
835
  }
851
836
  /**
852
- * 处理防抖后的同步消息批次
853
- *
854
- * product 模块:
855
- * - operation === 'delete' → 本地删除
856
- * - change_types 包含 price → SSE 增量拉取 + 刷新报价单价格缓存
857
- * - 有 body → body 完整数据直接覆盖本地
858
-
859
- *
860
- * product_collection / product_category / product_quotation:
861
- * - 按 relation_product_ids SSE 拉取受影响商品
862
- * - product_quotation 额外刷新报价单价格缓存
863
- *
864
- * 处理完成后 emit onProductsSyncCompleted 通知 Server 层
865
- */
837
+ * 处理防抖后的同步消息批次
838
+ *
839
+ * product 模块:
840
+ * - operation === 'delete' → 本地删除
841
+ * - change_types 包含 price → SSE 增量拉取
842
+ * - 有 body → body 完整数据直接覆盖本地
843
+ *
844
+ * product_collection / product_category / product_quotation:
845
+ * - relation_product_ids SSE 拉取受影响商品
846
+ *
847
+ * 处理完成后清除价格缓存并 emit onProductsSyncCompleted,
848
+ * Server 层监听该事件后重新查询,走完整的 formatter 管道重建缓存
849
+ */
866
850
  async processProductSyncMessages() {
867
851
  var _a, _b, _c, _d, _e;
868
852
  const messages = [...this.pendingSyncMessages];
@@ -873,7 +857,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
873
857
  const deleteIds = [];
874
858
  const bodyUpdates = /* @__PURE__ */ new Map();
875
859
  const sseRefreshIds = [];
876
- const priceRefreshIds = [];
877
860
  for (const msg of messages) {
878
861
  const channelKey = msg._channelKey || msg.module || "product";
879
862
  if (channelKey === "product") {
@@ -887,7 +870,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
887
870
  if ((_b = msg.change_types) == null ? void 0 : _b.includes("price")) {
888
871
  const ids = msg.ids || (msg.id ? [msg.id] : []);
889
872
  sseRefreshIds.push(...ids);
890
- priceRefreshIds.push(...ids);
891
873
  continue;
892
874
  }
893
875
  if (msg.body) {
@@ -907,16 +889,11 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
907
889
  } else if (["product_collection", "product_category", "product_quotation"].includes(channelKey)) {
908
890
  if ((_e = msg.relation_product_ids) == null ? void 0 : _e.length) {
909
891
  sseRefreshIds.push(...msg.relation_product_ids);
910
- if (channelKey === "product_quotation") {
911
- this.clearPriceCache();
912
- priceRefreshIds.push(...msg.relation_product_ids);
913
- }
914
892
  }
915
893
  }
916
894
  }
917
895
  const uniqueDeleteIds = [...new Set(deleteIds)];
918
896
  const uniqueSSEIds = [...new Set(sseRefreshIds)];
919
- const uniquePriceIds = [...new Set(priceRefreshIds)];
920
897
  if (uniqueDeleteIds.length > 0) {
921
898
  await this.removeProductsByIds(uniqueDeleteIds);
922
899
  }
@@ -927,28 +904,22 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
927
904
  const freshProducts = await this.fetchProductsBySSE(uniqueSSEIds);
928
905
  if (freshProducts.length > 0) {
929
906
  await this.mergeProductsToStore(freshProducts);
930
- await this.updatePriceCacheForProducts(freshProducts);
931
907
  }
932
908
  this.logInfo("processProductSyncMessages: SSE 增量更新完成", {
933
909
  requestedCount: uniqueSSEIds.length,
934
910
  receivedCount: freshProducts.length
935
911
  });
936
912
  }
937
- const sseHandledSet = new Set(uniqueSSEIds);
938
- const remainingPriceIds = uniquePriceIds.filter((id) => !sseHandledSet.has(id));
939
- if (remainingPriceIds.length > 0) {
940
- await this.updateProductPriceByIds(remainingPriceIds);
941
- }
942
913
  this.logInfo("processProductSyncMessages: 处理完成", {
943
914
  deleteCount: uniqueDeleteIds.length,
944
915
  bodyUpdateCount: bodyUpdates.size,
945
- sseRefreshCount: uniqueSSEIds.length,
946
- priceRefreshCount: uniquePriceIds.length
916
+ sseRefreshCount: uniqueSSEIds.length
947
917
  });
948
- if (uniqueDeleteIds.length === 0 && bodyUpdates.size === 0 && uniqueSSEIds.length === 0 && uniquePriceIds.length === 0) {
918
+ if (uniqueDeleteIds.length === 0 && bodyUpdates.size === 0 && uniqueSSEIds.length === 0) {
949
919
  this.logInfo("processProductSyncMessages: 没有变更,不触发 onProductsSyncCompleted");
950
920
  return;
951
921
  }
922
+ this.clearPriceCache();
952
923
  await this.core.effects.emit(import_types.ProductsHooks.onProductsSyncCompleted, null);
953
924
  }
954
925
  /**
@@ -983,7 +954,8 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
983
954
  /**
984
955
  * 将 body 完整数据直接覆盖到本地 store(不调用报价单接口)
985
956
  * 已存在的 → 直接替换;不存在的 → 追加
986
- * 同时更新 Map 缓存、IndexDB,清空价格缓存,触发 onProductsChanged
957
+ * 同时更新 Map 缓存、IndexDB,触发 onProductsChanged
958
+ * 价格缓存由 processProductSyncMessages 末尾统一清除
987
959
  */
988
960
  async applyBodyUpdatesToStore(bodyUpdates) {
989
961
  this.logInfo("applyBodyUpdatesToStore: 开始", { count: bodyUpdates.size });
@@ -1006,7 +978,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
1006
978
  }
1007
979
  this.syncProductsMap();
1008
980
  await this.saveProductsToIndexDB(this.store.list);
1009
- await this.updatePriceCacheForProducts([...bodyUpdates.values()]);
1010
981
  this.core.effects.emit(import_types.ProductsHooks.onProductsChanged, this.store.list);
1011
982
  this.logInfo("applyBodyUpdatesToStore: 完成", {
1012
983
  updatedCount,
@@ -1047,80 +1018,6 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
1047
1018
  });
1048
1019
  this.core.effects.emit(import_types.ProductsHooks.onProductsChanged, this.store.list);
1049
1020
  }
1050
- /**
1051
- * 增量更新价格缓存中变更的商品
1052
- * 对每个已缓存的日期 key:替换/追加最新商品数据,重新拉取这些 ID 的价格并应用
1053
- */
1054
- async updatePriceCacheForProducts(freshProducts) {
1055
- if (this.productsPriceCache.size === 0)
1056
- return;
1057
- const freshIds = freshProducts.map((p) => p.id);
1058
- const freshMap = /* @__PURE__ */ new Map();
1059
- for (const p of freshProducts) {
1060
- freshMap.set(p.id, p);
1061
- }
1062
- this.logInfo("updatePriceCacheForProducts: 开始", {
1063
- freshIds,
1064
- cachedDateCount: this.productsPriceCache.size
1065
- });
1066
- for (const [dateKey, cachedProducts] of this.productsPriceCache.entries()) {
1067
- try {
1068
- const updatedList = cachedProducts.map((p) => {
1069
- const fresh = freshMap.get(p.id);
1070
- return fresh ? { ...fresh } : p;
1071
- });
1072
- const existingIds = new Set(cachedProducts.map((p) => p.id));
1073
- for (const p of freshProducts) {
1074
- if (!existingIds.has(p.id)) {
1075
- updatedList.push({ ...p });
1076
- }
1077
- }
1078
- const priceData = await this.loadProductsPrice({
1079
- ids: freshIds,
1080
- schedule_date: dateKey
1081
- });
1082
- const result = priceData && priceData.length > 0 ? (0, import_product.applyPriceDataToProducts)(updatedList, priceData) : updatedList;
1083
- this.productsPriceCache.set(dateKey, result);
1084
- this.logInfo("updatePriceCacheForProducts: 日期缓存已更新", {
1085
- dateKey,
1086
- updatedIds: freshIds
1087
- });
1088
- } catch (error) {
1089
- const errorMessage = error instanceof Error ? error.message : String(error);
1090
- this.logError("updatePriceCacheForProducts: 失败", { dateKey, error: errorMessage });
1091
- }
1092
- }
1093
- }
1094
- /**
1095
- * 全量重新拉取报价单价格并重建价格缓存
1096
- * 遍历当前已缓存的所有日期 key,对每个日期重新调用 loadProductsPrice
1097
- */
1098
- async refreshAllPriceCache() {
1099
- const allProducts = this.getProductsRef();
1100
- if (allProducts.length === 0)
1101
- return;
1102
- const ids = allProducts.map((p) => p.id);
1103
- const dateKeys = Array.from(this.productsPriceCache.keys());
1104
- this.clearPriceCache();
1105
- if (dateKeys.length === 0) {
1106
- this.logInfo("refreshAllPriceCache: 无已缓存日期,跳过");
1107
- return;
1108
- }
1109
- this.logInfo("refreshAllPriceCache: 开始重新拉取", { dateKeys, productCount: ids.length });
1110
- for (const dateKey of dateKeys) {
1111
- try {
1112
- const priceData = await this.loadProductsPrice({ ids, schedule_date: dateKey });
1113
- if (priceData && priceData.length > 0) {
1114
- const updatedProducts = (0, import_product.applyPriceDataToProducts)(allProducts, priceData);
1115
- this.productsPriceCache.set(dateKey, updatedProducts);
1116
- }
1117
- this.logInfo("refreshAllPriceCache: 日期缓存已更新", { dateKey });
1118
- } catch (error) {
1119
- const errorMessage = error instanceof Error ? error.message : String(error);
1120
- this.logError("refreshAllPriceCache: 失败", { dateKey, error: errorMessage });
1121
- }
1122
- }
1123
- }
1124
1021
  /**
1125
1022
  * 静默全量刷新:后台重新拉取全量 SSE 数据并更新本地
1126
1023
  * 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.85",
4
+ "version": "2.2.87",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",