@pisell/pisellos 2.3.59 → 2.3.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/server/index.d.ts +6 -2
- package/dist/server/index.js +56 -28
- package/dist/server/modules/menu/index.js +48 -23
- package/dist/server/modules/order/index.d.ts +6 -2
- package/dist/server/modules/order/index.js +112 -58
- package/dist/server/modules/products/index.d.ts +6 -2
- package/dist/server/modules/products/index.js +150 -72
- package/lib/model/strategy/adapter/promotion/index.js +51 -0
- package/lib/server/index.d.ts +6 -2
- package/lib/server/index.js +18 -8
- package/lib/server/modules/menu/index.js +31 -5
- package/lib/server/modules/order/index.d.ts +6 -2
- package/lib/server/modules/order/index.js +38 -5
- package/lib/server/modules/products/index.d.ts +6 -2
- package/lib/server/modules/products/index.js +82 -20
- package/package.json +1 -1
|
@@ -1226,62 +1226,76 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1226
1226
|
key: "loadProductsByServer",
|
|
1227
1227
|
value: (function () {
|
|
1228
1228
|
var _loadProductsByServer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
1229
|
-
var
|
|
1229
|
+
var options,
|
|
1230
|
+
trigger,
|
|
1231
|
+
t0,
|
|
1232
|
+
tSSE,
|
|
1233
|
+
productList,
|
|
1234
|
+
list,
|
|
1235
|
+
duration,
|
|
1236
|
+
errorMessage,
|
|
1237
|
+
_args9 = arguments;
|
|
1230
1238
|
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
1231
1239
|
while (1) switch (_context9.prev = _context9.next) {
|
|
1232
1240
|
case 0:
|
|
1241
|
+
options = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
|
|
1233
1242
|
if (this.productDataSource) {
|
|
1234
|
-
_context9.next =
|
|
1243
|
+
_context9.next = 4;
|
|
1235
1244
|
break;
|
|
1236
1245
|
}
|
|
1237
1246
|
this.logWarning('loadProductsByServer: ProductDataSource 不可用');
|
|
1238
1247
|
return _context9.abrupt("return", []);
|
|
1239
|
-
case
|
|
1240
|
-
|
|
1248
|
+
case 4:
|
|
1249
|
+
trigger = options.trigger || 'unknown';
|
|
1250
|
+
this.logInfo('开始通过 DataSource SSE 加载商品列表', {
|
|
1251
|
+
trigger: trigger
|
|
1252
|
+
});
|
|
1241
1253
|
t0 = performance.now();
|
|
1242
|
-
_context9.prev =
|
|
1254
|
+
_context9.prev = 7;
|
|
1243
1255
|
tSSE = performance.now();
|
|
1244
|
-
_context9.next =
|
|
1256
|
+
_context9.next = 11;
|
|
1245
1257
|
return this.productDataSource.run({
|
|
1246
1258
|
sse: {}
|
|
1247
1259
|
});
|
|
1248
|
-
case
|
|
1260
|
+
case 11:
|
|
1249
1261
|
productList = _context9.sent;
|
|
1250
1262
|
list = productList || [];
|
|
1251
1263
|
perfMark('loadProductsByServer.SSE', performance.now() - tSSE, {
|
|
1252
1264
|
count: list.length
|
|
1253
1265
|
});
|
|
1254
1266
|
this.logInfo('通过 DataSource SSE 加载商品列表成功', {
|
|
1267
|
+
trigger: trigger,
|
|
1255
1268
|
productCount: list.length,
|
|
1256
1269
|
duration: "".concat(Math.round(performance.now() - t0), "ms")
|
|
1257
1270
|
});
|
|
1258
|
-
_context9.next =
|
|
1271
|
+
_context9.next = 17;
|
|
1259
1272
|
return this.replaceProductsSnapshotInIndexDB(list, 'loadProductsByServer');
|
|
1260
|
-
case
|
|
1273
|
+
case 17:
|
|
1261
1274
|
this.lastServerFullFetchAtMs = Date.now();
|
|
1262
|
-
_context9.next =
|
|
1275
|
+
_context9.next = 20;
|
|
1263
1276
|
return this.core.effects.emit(ProductsHooks.onProductsLoaded, list);
|
|
1264
|
-
case
|
|
1277
|
+
case 20:
|
|
1265
1278
|
perfMark('loadProductsByServer', performance.now() - t0, {
|
|
1266
1279
|
count: list.length
|
|
1267
1280
|
});
|
|
1268
1281
|
return _context9.abrupt("return", list);
|
|
1269
|
-
case
|
|
1270
|
-
_context9.prev =
|
|
1271
|
-
_context9.t0 = _context9["catch"](
|
|
1282
|
+
case 24:
|
|
1283
|
+
_context9.prev = 24;
|
|
1284
|
+
_context9.t0 = _context9["catch"](7);
|
|
1272
1285
|
duration = Math.round(performance.now() - t0);
|
|
1273
1286
|
errorMessage = _context9.t0 instanceof Error ? _context9.t0.message : String(_context9.t0);
|
|
1274
1287
|
console.error('[Products] 加载商品数据失败:', _context9.t0);
|
|
1275
1288
|
this.logError('通过 DataSource SSE 加载商品列表失败', {
|
|
1289
|
+
trigger: trigger,
|
|
1276
1290
|
duration: "".concat(duration, "ms"),
|
|
1277
1291
|
error: errorMessage
|
|
1278
1292
|
});
|
|
1279
1293
|
return _context9.abrupt("return", []);
|
|
1280
|
-
case
|
|
1294
|
+
case 31:
|
|
1281
1295
|
case "end":
|
|
1282
1296
|
return _context9.stop();
|
|
1283
1297
|
}
|
|
1284
|
-
}, _callee9, this, [[
|
|
1298
|
+
}, _callee9, this, [[7, 24]]);
|
|
1285
1299
|
}));
|
|
1286
1300
|
function loadProductsByServer() {
|
|
1287
1301
|
return _loadProductsByServer.apply(this, arguments);
|
|
@@ -1678,7 +1692,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1678
1692
|
tTotal = performance.now();
|
|
1679
1693
|
this.logInfo('refreshProducts 开始');
|
|
1680
1694
|
_context16.next = 4;
|
|
1681
|
-
return this.loadProductsByServer(
|
|
1695
|
+
return this.loadProductsByServer({
|
|
1696
|
+
trigger: 'product_sync'
|
|
1697
|
+
});
|
|
1682
1698
|
case 4:
|
|
1683
1699
|
products = _context16.sent;
|
|
1684
1700
|
if (products && products.length > 0) {
|
|
@@ -1770,7 +1786,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1770
1786
|
key: "loadProductsFromIndexDB",
|
|
1771
1787
|
value: (function () {
|
|
1772
1788
|
var _loadProductsFromIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
|
|
1773
|
-
var _products$length, _products$length2,
|
|
1789
|
+
var startedAt, _products$length, _products$length2, products, durationMs, errorMessage;
|
|
1774
1790
|
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1775
1791
|
while (1) switch (_context18.prev = _context18.next) {
|
|
1776
1792
|
case 0:
|
|
@@ -1781,33 +1797,36 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1781
1797
|
this.logWarning('loadProductsFromIndexDB: dbManager 不可用');
|
|
1782
1798
|
return _context18.abrupt("return", []);
|
|
1783
1799
|
case 3:
|
|
1784
|
-
|
|
1785
|
-
|
|
1800
|
+
startedAt = performance.now();
|
|
1801
|
+
_context18.prev = 4;
|
|
1786
1802
|
_context18.next = 7;
|
|
1787
1803
|
return this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
1788
1804
|
case 7:
|
|
1789
1805
|
products = _context18.sent;
|
|
1790
|
-
|
|
1806
|
+
durationMs = +(performance.now() - startedAt).toFixed(2);
|
|
1807
|
+
perfMark('loadProductsFromIndexDB', durationMs, {
|
|
1791
1808
|
count: (_products$length = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length !== void 0 ? _products$length : 0
|
|
1792
1809
|
});
|
|
1793
1810
|
this.logInfo('从 IndexDB 加载商品数据', {
|
|
1794
|
-
productCount: (_products$length2 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length2 !== void 0 ? _products$length2 : 0
|
|
1811
|
+
productCount: (_products$length2 = products === null || products === void 0 ? void 0 : products.length) !== null && _products$length2 !== void 0 ? _products$length2 : 0,
|
|
1812
|
+
durationMs: durationMs
|
|
1795
1813
|
});
|
|
1796
1814
|
return _context18.abrupt("return", products || []);
|
|
1797
|
-
case
|
|
1798
|
-
_context18.prev =
|
|
1799
|
-
_context18.t0 = _context18["catch"](
|
|
1815
|
+
case 14:
|
|
1816
|
+
_context18.prev = 14;
|
|
1817
|
+
_context18.t0 = _context18["catch"](4);
|
|
1800
1818
|
errorMessage = _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0);
|
|
1801
1819
|
console.error('[Products] 从 IndexDB 读取数据失败:', _context18.t0);
|
|
1802
1820
|
this.logError('从 IndexDB 读取数据失败', {
|
|
1821
|
+
durationMs: +(performance.now() - startedAt).toFixed(2),
|
|
1803
1822
|
error: errorMessage
|
|
1804
1823
|
});
|
|
1805
1824
|
return _context18.abrupt("return", []);
|
|
1806
|
-
case
|
|
1825
|
+
case 20:
|
|
1807
1826
|
case "end":
|
|
1808
1827
|
return _context18.stop();
|
|
1809
1828
|
}
|
|
1810
|
-
}, _callee18, this, [[
|
|
1829
|
+
}, _callee18, this, [[4, 14]]);
|
|
1811
1830
|
}));
|
|
1812
1831
|
function loadProductsFromIndexDB() {
|
|
1813
1832
|
return _loadProductsFromIndexDB.apply(this, arguments);
|
|
@@ -1861,7 +1880,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1861
1880
|
value: (function () {
|
|
1862
1881
|
var _replaceProductsSnapshotInIndexDB = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(products, source) {
|
|
1863
1882
|
var _this9 = this;
|
|
1864
|
-
var errorMessage;
|
|
1883
|
+
var enqueuedAt, queueWaitMs, clearDurationMs, writeDurationMs, errorMessage;
|
|
1865
1884
|
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1866
1885
|
while (1) switch (_context21.prev = _context21.next) {
|
|
1867
1886
|
case 0:
|
|
@@ -1872,58 +1891,86 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1872
1891
|
this.logWarning('replaceProductsSnapshotInIndexDB: dbManager 不可用');
|
|
1873
1892
|
return _context21.abrupt("return");
|
|
1874
1893
|
case 3:
|
|
1875
|
-
|
|
1876
|
-
|
|
1894
|
+
enqueuedAt = performance.now();
|
|
1895
|
+
queueWaitMs = 0;
|
|
1896
|
+
clearDurationMs = 0;
|
|
1897
|
+
writeDurationMs = 0;
|
|
1898
|
+
_context21.prev = 7;
|
|
1899
|
+
_context21.next = 10;
|
|
1877
1900
|
return this.runInProductIndexDBSaveQueue( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
|
|
1878
|
-
var
|
|
1901
|
+
var operationStartedAt, clearStartedAt, writeStartedAt, executeDurationMs;
|
|
1879
1902
|
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1880
1903
|
while (1) switch (_context20.prev = _context20.next) {
|
|
1881
1904
|
case 0:
|
|
1905
|
+
operationStartedAt = performance.now();
|
|
1906
|
+
queueWaitMs = +(operationStartedAt - enqueuedAt).toFixed(2);
|
|
1882
1907
|
_this9.logInfo('replaceProductsSnapshotInIndexDB 开始', {
|
|
1883
1908
|
source: source,
|
|
1884
|
-
productCount: products.length
|
|
1909
|
+
productCount: products.length,
|
|
1910
|
+
queueWaitMs: queueWaitMs
|
|
1885
1911
|
});
|
|
1886
|
-
|
|
1887
|
-
_context20.
|
|
1912
|
+
clearStartedAt = performance.now();
|
|
1913
|
+
_context20.prev = 4;
|
|
1914
|
+
_context20.next = 7;
|
|
1888
1915
|
return _this9.dbManager.clear(INDEXDB_STORE_NAME);
|
|
1889
|
-
case
|
|
1916
|
+
case 7:
|
|
1917
|
+
_context20.prev = 7;
|
|
1918
|
+
clearDurationMs = +(performance.now() - clearStartedAt).toFixed(2);
|
|
1919
|
+
return _context20.finish(7);
|
|
1920
|
+
case 10:
|
|
1890
1921
|
if (!(products.length > 0)) {
|
|
1891
|
-
_context20.next =
|
|
1922
|
+
_context20.next = 18;
|
|
1892
1923
|
break;
|
|
1893
1924
|
}
|
|
1894
|
-
|
|
1925
|
+
writeStartedAt = performance.now();
|
|
1926
|
+
_context20.prev = 12;
|
|
1927
|
+
_context20.next = 15;
|
|
1895
1928
|
return _this9.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
|
|
1896
|
-
case
|
|
1897
|
-
|
|
1929
|
+
case 15:
|
|
1930
|
+
_context20.prev = 15;
|
|
1931
|
+
writeDurationMs = +(performance.now() - writeStartedAt).toFixed(2);
|
|
1932
|
+
return _context20.finish(15);
|
|
1933
|
+
case 18:
|
|
1934
|
+
executeDurationMs = +(performance.now() - operationStartedAt).toFixed(2);
|
|
1935
|
+
perfMark('replaceProductsSnapshotInIndexDB', executeDurationMs, {
|
|
1898
1936
|
count: products.length
|
|
1899
1937
|
});
|
|
1900
1938
|
_this9.logInfo('replaceProductsSnapshotInIndexDB 完成', {
|
|
1901
1939
|
source: source,
|
|
1902
|
-
productCount: products.length
|
|
1940
|
+
productCount: products.length,
|
|
1941
|
+
queueWaitMs: queueWaitMs,
|
|
1942
|
+
clearDurationMs: clearDurationMs,
|
|
1943
|
+
writeDurationMs: writeDurationMs,
|
|
1944
|
+
executeDurationMs: executeDurationMs,
|
|
1945
|
+
totalDurationMs: +(performance.now() - enqueuedAt).toFixed(2)
|
|
1903
1946
|
});
|
|
1904
|
-
case
|
|
1947
|
+
case 21:
|
|
1905
1948
|
case "end":
|
|
1906
1949
|
return _context20.stop();
|
|
1907
1950
|
}
|
|
1908
|
-
}, _callee20);
|
|
1951
|
+
}, _callee20, null, [[4,, 7, 10], [12,, 15, 18]]);
|
|
1909
1952
|
})));
|
|
1910
|
-
case
|
|
1911
|
-
_context21.next =
|
|
1953
|
+
case 10:
|
|
1954
|
+
_context21.next = 16;
|
|
1912
1955
|
break;
|
|
1913
|
-
case
|
|
1914
|
-
_context21.prev =
|
|
1915
|
-
_context21.t0 = _context21["catch"](
|
|
1956
|
+
case 12:
|
|
1957
|
+
_context21.prev = 12;
|
|
1958
|
+
_context21.t0 = _context21["catch"](7);
|
|
1916
1959
|
errorMessage = _context21.t0 instanceof Error ? _context21.t0.message : String(_context21.t0);
|
|
1917
1960
|
this.logError('全量保存商品到 IndexDB 失败', {
|
|
1918
1961
|
source: source,
|
|
1919
1962
|
productCount: products.length,
|
|
1963
|
+
queueWaitMs: queueWaitMs,
|
|
1964
|
+
clearDurationMs: clearDurationMs,
|
|
1965
|
+
writeDurationMs: writeDurationMs,
|
|
1966
|
+
totalDurationMs: +(performance.now() - enqueuedAt).toFixed(2),
|
|
1920
1967
|
error: errorMessage
|
|
1921
1968
|
});
|
|
1922
|
-
case
|
|
1969
|
+
case 16:
|
|
1923
1970
|
case "end":
|
|
1924
1971
|
return _context21.stop();
|
|
1925
1972
|
}
|
|
1926
|
-
}, _callee21, this, [[
|
|
1973
|
+
}, _callee21, this, [[7, 12]]);
|
|
1927
1974
|
}));
|
|
1928
1975
|
function replaceProductsSnapshotInIndexDB(_x21, _x22) {
|
|
1929
1976
|
return _replaceProductsSnapshotInIndexDB.apply(this, arguments);
|
|
@@ -2124,6 +2171,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2124
2171
|
source: 'IndexDB'
|
|
2125
2172
|
});
|
|
2126
2173
|
this.logInfo('预加载完成(从 IndexDB)', {
|
|
2174
|
+
trigger: 'preload',
|
|
2127
2175
|
productCount: cachedData.length,
|
|
2128
2176
|
duration: "".concat(Math.round(performance.now() - tTotal), "ms"),
|
|
2129
2177
|
source: 'IndexDB'
|
|
@@ -2146,7 +2194,9 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2146
2194
|
case 29:
|
|
2147
2195
|
tServer = performance.now();
|
|
2148
2196
|
_context24.next = 32;
|
|
2149
|
-
return this.loadProductsByServer(
|
|
2197
|
+
return this.loadProductsByServer({
|
|
2198
|
+
trigger: 'preload'
|
|
2199
|
+
});
|
|
2150
2200
|
case 32:
|
|
2151
2201
|
products = _context24.sent;
|
|
2152
2202
|
perfMark('preload.loadFromServer', performance.now() - tServer, {
|
|
@@ -2166,6 +2216,7 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2166
2216
|
source: 'Server'
|
|
2167
2217
|
});
|
|
2168
2218
|
this.logInfo('预加载完成(从服务器)', {
|
|
2219
|
+
trigger: 'preload',
|
|
2169
2220
|
productCount: products.length,
|
|
2170
2221
|
duration: "".concat(Math.round(performance.now() - tTotal), "ms"),
|
|
2171
2222
|
source: 'Server'
|
|
@@ -2790,64 +2841,91 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2790
2841
|
key: "silentRefresh",
|
|
2791
2842
|
value: (function () {
|
|
2792
2843
|
var _silentRefresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
|
|
2793
|
-
var
|
|
2844
|
+
var options,
|
|
2845
|
+
t0,
|
|
2846
|
+
now,
|
|
2847
|
+
trigger,
|
|
2848
|
+
elapsedSincePreloadMs,
|
|
2849
|
+
elapsedSinceFullFetchMs,
|
|
2850
|
+
products,
|
|
2851
|
+
errorMessage,
|
|
2852
|
+
_args29 = arguments;
|
|
2794
2853
|
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
2795
2854
|
while (1) switch (_context29.prev = _context29.next) {
|
|
2796
2855
|
case 0:
|
|
2856
|
+
options = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
|
|
2797
2857
|
t0 = performance.now();
|
|
2798
2858
|
now = Date.now();
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2859
|
+
trigger = options.trigger || 'background';
|
|
2860
|
+
elapsedSincePreloadMs = now - this.lastPreloadCompletedAtMs;
|
|
2861
|
+
elapsedSinceFullFetchMs = now - this.lastServerFullFetchAtMs;
|
|
2862
|
+
if (!(this.lastPreloadCompletedAtMs > 0 && elapsedSincePreloadMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetchMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS)) {
|
|
2863
|
+
_context29.next = 9;
|
|
2803
2864
|
break;
|
|
2804
2865
|
}
|
|
2866
|
+
this.logInfo('silentRefresh 跳过全量 SSE', {
|
|
2867
|
+
trigger: trigger,
|
|
2868
|
+
reason: 'within_min_interval',
|
|
2869
|
+
minIntervalMs: PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS,
|
|
2870
|
+
elapsedSincePreloadMs: elapsedSincePreloadMs,
|
|
2871
|
+
elapsedSinceFullFetchMs: elapsedSinceFullFetchMs,
|
|
2872
|
+
productCount: this.store.list.length
|
|
2873
|
+
});
|
|
2805
2874
|
return _context29.abrupt("return", this.store.list);
|
|
2806
|
-
case
|
|
2807
|
-
this.logInfo('silentRefresh 开始'
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2875
|
+
case 9:
|
|
2876
|
+
this.logInfo('silentRefresh 开始', {
|
|
2877
|
+
trigger: trigger,
|
|
2878
|
+
elapsedSincePreloadMs: elapsedSincePreloadMs,
|
|
2879
|
+
elapsedSinceFullFetchMs: elapsedSinceFullFetchMs,
|
|
2880
|
+
productCount: this.store.list.length
|
|
2881
|
+
});
|
|
2882
|
+
_context29.prev = 10;
|
|
2883
|
+
_context29.next = 13;
|
|
2884
|
+
return this.loadProductsByServer({
|
|
2885
|
+
trigger: trigger
|
|
2886
|
+
});
|
|
2887
|
+
case 13:
|
|
2812
2888
|
products = _context29.sent;
|
|
2813
2889
|
if (!(products && products.length > 0)) {
|
|
2814
|
-
_context29.next =
|
|
2890
|
+
_context29.next = 24;
|
|
2815
2891
|
break;
|
|
2816
2892
|
}
|
|
2817
2893
|
this.store.list = products;
|
|
2818
2894
|
this.syncProductsMap();
|
|
2819
2895
|
this.clearPriceCache();
|
|
2820
2896
|
this.core.effects.emit(ProductsHooks.onProductsChanged, this.store.list);
|
|
2821
|
-
_context29.next =
|
|
2897
|
+
_context29.next = 21;
|
|
2822
2898
|
return this.core.effects.emit(ProductsHooks.onProductsSyncCompleted, null);
|
|
2823
|
-
case
|
|
2899
|
+
case 21:
|
|
2824
2900
|
this.logInfo('silentRefresh 完成', {
|
|
2901
|
+
trigger: trigger,
|
|
2825
2902
|
productCount: products.length,
|
|
2826
2903
|
duration: "".concat(Math.round(performance.now() - t0), "ms")
|
|
2827
2904
|
});
|
|
2828
|
-
_context29.next =
|
|
2905
|
+
_context29.next = 25;
|
|
2829
2906
|
break;
|
|
2830
|
-
case
|
|
2907
|
+
case 24:
|
|
2831
2908
|
this.logWarning('silentRefresh: 服务器未返回数据');
|
|
2832
|
-
case
|
|
2909
|
+
case 25:
|
|
2833
2910
|
perfMark('silentRefresh', performance.now() - t0, {
|
|
2834
2911
|
count: this.store.list.length
|
|
2835
2912
|
});
|
|
2836
2913
|
return _context29.abrupt("return", this.store.list);
|
|
2837
|
-
case
|
|
2838
|
-
_context29.prev =
|
|
2839
|
-
_context29.t0 = _context29["catch"](
|
|
2914
|
+
case 29:
|
|
2915
|
+
_context29.prev = 29;
|
|
2916
|
+
_context29.t0 = _context29["catch"](10);
|
|
2840
2917
|
errorMessage = _context29.t0 instanceof Error ? _context29.t0.message : String(_context29.t0);
|
|
2841
2918
|
this.logError('silentRefresh 失败', {
|
|
2919
|
+
trigger: trigger,
|
|
2842
2920
|
duration: "".concat(Math.round(performance.now() - t0), "ms"),
|
|
2843
2921
|
error: errorMessage
|
|
2844
2922
|
});
|
|
2845
2923
|
return _context29.abrupt("return", this.store.list);
|
|
2846
|
-
case
|
|
2924
|
+
case 34:
|
|
2847
2925
|
case "end":
|
|
2848
2926
|
return _context29.stop();
|
|
2849
2927
|
}
|
|
2850
|
-
}, _callee29, this, [[
|
|
2928
|
+
}, _callee29, this, [[10, 29]]);
|
|
2851
2929
|
}));
|
|
2852
2930
|
function silentRefresh() {
|
|
2853
2931
|
return _silentRefresh.apply(this, arguments);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/model/strategy/adapter/promotion/index.ts
|
|
30
|
+
var promotion_exports = {};
|
|
31
|
+
__export(promotion_exports, {
|
|
32
|
+
BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
|
|
33
|
+
ITEM_REWARD_STRATEGY: () => import_examples.ITEM_REWARD_STRATEGY,
|
|
34
|
+
PromotionAdapter: () => import_adapter.PromotionAdapter,
|
|
35
|
+
PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
|
|
36
|
+
X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
|
|
37
|
+
default: () => import_adapter2.default
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(promotion_exports);
|
|
40
|
+
var import_evaluator = require("./evaluator");
|
|
41
|
+
var import_adapter = require("./adapter");
|
|
42
|
+
var import_adapter2 = __toESM(require("./adapter"));
|
|
43
|
+
var import_examples = require("./examples");
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
BUY_X_GET_Y_FREE_STRATEGY,
|
|
47
|
+
ITEM_REWARD_STRATEGY,
|
|
48
|
+
PromotionAdapter,
|
|
49
|
+
PromotionEvaluator,
|
|
50
|
+
X_ITEMS_FOR_Y_PRICE_STRATEGY
|
|
51
|
+
});
|
package/lib/server/index.d.ts
CHANGED
|
@@ -157,13 +157,17 @@ declare class Server {
|
|
|
157
157
|
* 重新拉取全量 SSE 接口,更新本地数据后触发 onProductsSyncCompleted
|
|
158
158
|
* 不影响当前界面展示,适用于切回前台、定时刷新等场景
|
|
159
159
|
*/
|
|
160
|
-
refreshProductsInBackground(
|
|
160
|
+
refreshProductsInBackground(options?: {
|
|
161
|
+
trigger?: string;
|
|
162
|
+
}): Promise<void>;
|
|
161
163
|
/**
|
|
162
164
|
* 后台静默刷新订单数据
|
|
163
165
|
* 重新拉取全量 SSE 接口,更新本地数据后触发 onOrdersSyncCompleted
|
|
164
166
|
* 不影响当前界面展示,适用于切回前台、定时刷新等场景
|
|
165
167
|
*/
|
|
166
|
-
refreshOrdersInBackground(
|
|
168
|
+
refreshOrdersInBackground(options?: {
|
|
169
|
+
trigger?: string;
|
|
170
|
+
}): Promise<void>;
|
|
167
171
|
/**
|
|
168
172
|
* 编辑正式订单时强制查询 Server 最新快照并覆盖本地缓存。
|
|
169
173
|
* 商品成员增删由 OrderModule 在 SQLite/Store 更新完成后广播,
|
package/lib/server/index.js
CHANGED
|
@@ -1761,22 +1761,27 @@ var Server = class {
|
|
|
1761
1761
|
* 重新拉取全量 SSE 接口,更新本地数据后触发 onProductsSyncCompleted
|
|
1762
1762
|
* 不影响当前界面展示,适用于切回前台、定时刷新等场景
|
|
1763
1763
|
*/
|
|
1764
|
-
async refreshProductsInBackground() {
|
|
1764
|
+
async refreshProductsInBackground(options = {}) {
|
|
1765
1765
|
if (!this.products) {
|
|
1766
1766
|
this.logWarning("refreshProductsInBackground: Products 模块未注册");
|
|
1767
1767
|
return;
|
|
1768
1768
|
}
|
|
1769
|
-
|
|
1769
|
+
const trigger = options.trigger || "background";
|
|
1770
|
+
this.logInfo("refreshProductsInBackground 开始", { trigger });
|
|
1770
1771
|
const startTime = Date.now();
|
|
1771
1772
|
try {
|
|
1772
|
-
await this.products.silentRefresh();
|
|
1773
|
+
await this.products.silentRefresh({ trigger });
|
|
1773
1774
|
const duration = Date.now() - startTime;
|
|
1774
|
-
this.logInfo("refreshProductsInBackground 完成", {
|
|
1775
|
+
this.logInfo("refreshProductsInBackground 完成", {
|
|
1776
|
+
trigger,
|
|
1777
|
+
duration: `${duration}ms`
|
|
1778
|
+
});
|
|
1775
1779
|
} catch (error) {
|
|
1776
1780
|
const duration = Date.now() - startTime;
|
|
1777
1781
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1778
1782
|
console.error("[Server] refreshProductsInBackground 失败:", error);
|
|
1779
1783
|
this.logError("refreshProductsInBackground 失败", {
|
|
1784
|
+
trigger,
|
|
1780
1785
|
duration: `${duration}ms`,
|
|
1781
1786
|
error: errorMessage
|
|
1782
1787
|
});
|
|
@@ -1787,22 +1792,27 @@ var Server = class {
|
|
|
1787
1792
|
* 重新拉取全量 SSE 接口,更新本地数据后触发 onOrdersSyncCompleted
|
|
1788
1793
|
* 不影响当前界面展示,适用于切回前台、定时刷新等场景
|
|
1789
1794
|
*/
|
|
1790
|
-
async refreshOrdersInBackground() {
|
|
1795
|
+
async refreshOrdersInBackground(options = {}) {
|
|
1791
1796
|
if (!this.order) {
|
|
1792
1797
|
this.logWarning("refreshOrdersInBackground: Order 模块未注册");
|
|
1793
1798
|
return;
|
|
1794
1799
|
}
|
|
1795
|
-
|
|
1800
|
+
const trigger = options.trigger || "background";
|
|
1801
|
+
this.logInfo("refreshOrdersInBackground 开始", { trigger });
|
|
1796
1802
|
const startTime = Date.now();
|
|
1797
1803
|
try {
|
|
1798
|
-
await this.order.silentRefresh();
|
|
1804
|
+
await this.order.silentRefresh({ trigger });
|
|
1799
1805
|
const duration = Date.now() - startTime;
|
|
1800
|
-
this.logInfo("refreshOrdersInBackground 完成", {
|
|
1806
|
+
this.logInfo("refreshOrdersInBackground 完成", {
|
|
1807
|
+
trigger,
|
|
1808
|
+
duration: `${duration}ms`
|
|
1809
|
+
});
|
|
1801
1810
|
} catch (error) {
|
|
1802
1811
|
const duration = Date.now() - startTime;
|
|
1803
1812
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1804
1813
|
console.error("[Server] refreshOrdersInBackground 失败:", error);
|
|
1805
1814
|
this.logError("refreshOrdersInBackground 失败", {
|
|
1815
|
+
trigger,
|
|
1806
1816
|
duration: `${duration}ms`,
|
|
1807
1817
|
error: errorMessage
|
|
1808
1818
|
});
|
|
@@ -185,16 +185,21 @@ var MenuModule = class extends import_BaseModule.BaseModule {
|
|
|
185
185
|
this.logWarning("loadMenuFromIndexDB: dbManager 不可用");
|
|
186
186
|
return [];
|
|
187
187
|
}
|
|
188
|
+
const startedAt = performance.now();
|
|
188
189
|
try {
|
|
189
190
|
const menuList = await this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
190
191
|
this.logInfo("从 IndexDB 加载餐牌数据", {
|
|
191
|
-
menuCount: (menuList == null ? void 0 : menuList.length) ?? 0
|
|
192
|
+
menuCount: (menuList == null ? void 0 : menuList.length) ?? 0,
|
|
193
|
+
durationMs: +(performance.now() - startedAt).toFixed(2)
|
|
192
194
|
});
|
|
193
195
|
return menuList || [];
|
|
194
196
|
} catch (error) {
|
|
195
197
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
196
198
|
console.error("[Menu] 从 IndexDB 读取数据失败:", error);
|
|
197
|
-
this.logError("从 IndexDB 读取数据失败", {
|
|
199
|
+
this.logError("从 IndexDB 读取数据失败", {
|
|
200
|
+
durationMs: +(performance.now() - startedAt).toFixed(2),
|
|
201
|
+
error: errorMessage
|
|
202
|
+
});
|
|
198
203
|
return [];
|
|
199
204
|
}
|
|
200
205
|
}
|
|
@@ -207,20 +212,41 @@ var MenuModule = class extends import_BaseModule.BaseModule {
|
|
|
207
212
|
this.logWarning("saveMenuToIndexDB: dbManager 不可用");
|
|
208
213
|
return;
|
|
209
214
|
}
|
|
215
|
+
const startedAt = performance.now();
|
|
216
|
+
let clearDurationMs = 0;
|
|
217
|
+
let writeDurationMs = 0;
|
|
210
218
|
this.logInfo("开始保存餐牌数据到 IndexDB", { menuCount: menuList.length });
|
|
211
219
|
try {
|
|
212
|
-
|
|
220
|
+
const clearStartedAt = performance.now();
|
|
221
|
+
try {
|
|
222
|
+
await this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
223
|
+
} finally {
|
|
224
|
+
clearDurationMs = +(performance.now() - clearStartedAt).toFixed(2);
|
|
225
|
+
}
|
|
226
|
+
const writeStartedAt = performance.now();
|
|
213
227
|
const savePromises = menuList.map(
|
|
214
228
|
(menu) => this.dbManager.add(INDEXDB_STORE_NAME, menu)
|
|
215
229
|
);
|
|
216
|
-
|
|
230
|
+
try {
|
|
231
|
+
await Promise.all(savePromises);
|
|
232
|
+
} finally {
|
|
233
|
+
writeDurationMs = +(performance.now() - writeStartedAt).toFixed(2);
|
|
234
|
+
}
|
|
217
235
|
console.log(`[Menu] 已将 ${menuList.length} 条餐牌数据保存到 IndexDB`);
|
|
218
|
-
this.logInfo("餐牌数据已保存到 IndexDB", {
|
|
236
|
+
this.logInfo("餐牌数据已保存到 IndexDB", {
|
|
237
|
+
menuCount: menuList.length,
|
|
238
|
+
clearDurationMs,
|
|
239
|
+
writeDurationMs,
|
|
240
|
+
totalDurationMs: +(performance.now() - startedAt).toFixed(2)
|
|
241
|
+
});
|
|
219
242
|
} catch (error) {
|
|
220
243
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
221
244
|
console.error("[Menu] 保存数据到 IndexDB 失败:", error);
|
|
222
245
|
this.logError("保存数据到 IndexDB 失败", {
|
|
223
246
|
menuCount: menuList.length,
|
|
247
|
+
clearDurationMs,
|
|
248
|
+
writeDurationMs,
|
|
249
|
+
totalDurationMs: +(performance.now() - startedAt).toFixed(2),
|
|
224
250
|
error: errorMessage
|
|
225
251
|
});
|
|
226
252
|
}
|
|
@@ -119,13 +119,17 @@ export declare class OrderModule extends BaseModule implements Module {
|
|
|
119
119
|
payment: Record<string, any>;
|
|
120
120
|
previousPayment: Record<string, any>;
|
|
121
121
|
} | null>;
|
|
122
|
-
loadOrdersByServer(
|
|
122
|
+
loadOrdersByServer(options?: {
|
|
123
|
+
trigger?: string;
|
|
124
|
+
}): Promise<OrderData[]>;
|
|
123
125
|
/**
|
|
124
126
|
* 静默全量刷新:后台重新拉取全量 SSE 订单数据并更新本地
|
|
125
127
|
* 拿到完整数据后一次性替换 store,触发订单变更与同步完成事件
|
|
126
128
|
* @returns 刷新后的订单列表
|
|
127
129
|
*/
|
|
128
|
-
silentRefresh(
|
|
130
|
+
silentRefresh(options?: {
|
|
131
|
+
trigger?: string;
|
|
132
|
+
}): Promise<OrderData[]>;
|
|
129
133
|
private normalizeOrderForMemoryList;
|
|
130
134
|
private normalizeOrdersForMemoryList;
|
|
131
135
|
private hasRealOrderId;
|