@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
|
@@ -525,6 +525,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
525
525
|
return DEFAULT_ORDER_SYNC_THROTTLE_MS;
|
|
526
526
|
}
|
|
527
527
|
async preload() {
|
|
528
|
+
const preloadStartedAt = Date.now();
|
|
528
529
|
let cachedOrders = null;
|
|
529
530
|
if (this.dbManager) {
|
|
530
531
|
try {
|
|
@@ -544,13 +545,27 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
544
545
|
this.syncOrdersMap();
|
|
545
546
|
await this.core.effects.emit(import_types.OrderHooks.onOrdersLoaded, this.store.list);
|
|
546
547
|
await this.emitOrdersChanged([], "preload.sqlite");
|
|
548
|
+
this.logInfo("预加载完成", {
|
|
549
|
+
trigger: "preload",
|
|
550
|
+
source: "SQLite",
|
|
551
|
+
orderCount: this.store.list.length,
|
|
552
|
+
duration: `${Date.now() - preloadStartedAt}ms`
|
|
553
|
+
});
|
|
547
554
|
return;
|
|
548
555
|
}
|
|
549
|
-
const orders = await this.loadOrdersByServer(
|
|
556
|
+
const orders = await this.loadOrdersByServer({
|
|
557
|
+
trigger: "preload"
|
|
558
|
+
});
|
|
550
559
|
this.store.list = (0, import_lodash_es.cloneDeep)(orders);
|
|
551
560
|
this.syncOrdersMap();
|
|
552
561
|
await this.emitOrdersChanged([], "preload");
|
|
553
562
|
await this.core.effects.emit(import_types.OrderHooks.onOrdersSyncCompleted, null);
|
|
563
|
+
this.logInfo("预加载完成", {
|
|
564
|
+
trigger: "preload",
|
|
565
|
+
source: "Server",
|
|
566
|
+
orderCount: this.store.list.length,
|
|
567
|
+
duration: `${Date.now() - preloadStartedAt}ms`
|
|
568
|
+
});
|
|
554
569
|
}
|
|
555
570
|
getOrders() {
|
|
556
571
|
return this.store.list;
|
|
@@ -771,14 +786,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
771
786
|
this.logInfo("updateLocalPayment-变更事件完成", paymentContext);
|
|
772
787
|
return { order: nextOrder, payment: nextPayment, previousPayment };
|
|
773
788
|
}
|
|
774
|
-
async loadOrdersByServer() {
|
|
789
|
+
async loadOrdersByServer(options = {}) {
|
|
775
790
|
var _a;
|
|
776
791
|
let orderList = [];
|
|
777
792
|
let hasFetchedRemoteSnapshot = false;
|
|
793
|
+
const trigger = options.trigger || "unknown";
|
|
778
794
|
const protectedOrdersBeforeRemoteFetch = (await this.loadOrdersFromSQLite()).filter(
|
|
779
795
|
(order) => this.shouldProtectLocalOrderFromRemoteSnapshot(order)
|
|
780
796
|
);
|
|
781
797
|
this.logInfo("loadOrdersByServer-开始", {
|
|
798
|
+
trigger,
|
|
782
799
|
hasOrderDataSource: !!this.orderDataSource,
|
|
783
800
|
query: ((_a = this.store) == null ? void 0 : _a.createdAtQuery) || null,
|
|
784
801
|
protectedLocalOrderCount: protectedOrdersBeforeRemoteFetch.length,
|
|
@@ -796,6 +813,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
796
813
|
});
|
|
797
814
|
orderList = data || [];
|
|
798
815
|
this.logInfo("loadOrdersByServer-SSE拉取成功", {
|
|
816
|
+
trigger,
|
|
799
817
|
count: orderList.length
|
|
800
818
|
});
|
|
801
819
|
hasFetchedRemoteSnapshot = true;
|
|
@@ -824,6 +842,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
824
842
|
"loadOrdersByServer.memory"
|
|
825
843
|
);
|
|
826
844
|
this.logInfo("loadOrdersByServer-结束", {
|
|
845
|
+
trigger,
|
|
827
846
|
count: memoryOrders.length,
|
|
828
847
|
persistedCount: mergedOrders.length,
|
|
829
848
|
sqliteOnlyDraftCount: mergedOrders.length - memoryOrders.length
|
|
@@ -836,21 +855,34 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
836
855
|
* 拿到完整数据后一次性替换 store,触发订单变更与同步完成事件
|
|
837
856
|
* @returns 刷新后的订单列表
|
|
838
857
|
*/
|
|
839
|
-
async silentRefresh() {
|
|
858
|
+
async silentRefresh(options = {}) {
|
|
840
859
|
const startTime = Date.now();
|
|
860
|
+
const trigger = options.trigger || "background";
|
|
841
861
|
const elapsedSinceFullFetch = Date.now() - this.lastServerFullFetchAtMs;
|
|
842
862
|
if (this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetch < ORDER_SILENT_REFRESH_MIN_INTERVAL_MS) {
|
|
863
|
+
this.logInfo("silentRefresh 跳过全量 SSE", {
|
|
864
|
+
trigger,
|
|
865
|
+
reason: "within_min_interval",
|
|
866
|
+
minIntervalMs: ORDER_SILENT_REFRESH_MIN_INTERVAL_MS,
|
|
867
|
+
elapsedSinceFullFetchMs: elapsedSinceFullFetch,
|
|
868
|
+
orderCount: this.store.list.length
|
|
869
|
+
});
|
|
843
870
|
return this.store.list;
|
|
844
871
|
}
|
|
845
|
-
this.logInfo("silentRefresh 开始"
|
|
872
|
+
this.logInfo("silentRefresh 开始", {
|
|
873
|
+
trigger,
|
|
874
|
+
elapsedSinceFullFetchMs: elapsedSinceFullFetch,
|
|
875
|
+
orderCount: this.store.list.length
|
|
876
|
+
});
|
|
846
877
|
try {
|
|
847
878
|
this.updateCreateStore();
|
|
848
|
-
const orders = await this.loadOrdersByServer();
|
|
879
|
+
const orders = await this.loadOrdersByServer({ trigger });
|
|
849
880
|
this.store.list = (0, import_lodash_es.cloneDeep)(orders);
|
|
850
881
|
this.syncOrdersMap();
|
|
851
882
|
await this.emitOrdersChanged([], "silentRefresh");
|
|
852
883
|
await this.core.effects.emit(import_types.OrderHooks.onOrdersSyncCompleted, null);
|
|
853
884
|
this.logInfo("silentRefresh 完成", {
|
|
885
|
+
trigger,
|
|
854
886
|
orderCount: orders.length,
|
|
855
887
|
duration: `${Date.now() - startTime}ms`
|
|
856
888
|
});
|
|
@@ -858,6 +890,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
858
890
|
} catch (error) {
|
|
859
891
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
860
892
|
this.logError("silentRefresh 失败", {
|
|
893
|
+
trigger,
|
|
861
894
|
duration: `${Date.now() - startTime}ms`,
|
|
862
895
|
error: errorMessage
|
|
863
896
|
});
|
|
@@ -183,7 +183,9 @@ export declare class ProductsModule extends BaseModule implements Module {
|
|
|
183
183
|
/**
|
|
184
184
|
* 通过 ProductDataSource SSE 加载完整商品列表
|
|
185
185
|
*/
|
|
186
|
-
loadProductsByServer(
|
|
186
|
+
loadProductsByServer(options?: {
|
|
187
|
+
trigger?: string;
|
|
188
|
+
}): Promise<any>;
|
|
187
189
|
/**
|
|
188
190
|
* 纯请求方法:通过 HTTP 接口获取商品列表(无副作用,不触发事件、不写 IndexDB)
|
|
189
191
|
* @param params 查询参数
|
|
@@ -333,7 +335,9 @@ export declare class ProductsModule extends BaseModule implements Module {
|
|
|
333
335
|
* 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
|
|
334
336
|
* @returns 刷新后的商品列表
|
|
335
337
|
*/
|
|
336
|
-
silentRefresh(
|
|
338
|
+
silentRefresh(options?: {
|
|
339
|
+
trigger?: string;
|
|
340
|
+
}): Promise<ProductData[]>;
|
|
337
341
|
/**
|
|
338
342
|
* 销毁同步资源(取消 pubsub 订阅、清除定时器)
|
|
339
343
|
*/
|
|
@@ -814,12 +814,13 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
814
814
|
/**
|
|
815
815
|
* 通过 ProductDataSource SSE 加载完整商品列表
|
|
816
816
|
*/
|
|
817
|
-
async loadProductsByServer() {
|
|
817
|
+
async loadProductsByServer(options = {}) {
|
|
818
818
|
if (!this.productDataSource) {
|
|
819
819
|
this.logWarning("loadProductsByServer: ProductDataSource 不可用");
|
|
820
820
|
return [];
|
|
821
821
|
}
|
|
822
|
-
|
|
822
|
+
const trigger = options.trigger || "unknown";
|
|
823
|
+
this.logInfo("开始通过 DataSource SSE 加载商品列表", { trigger });
|
|
823
824
|
const t0 = performance.now();
|
|
824
825
|
try {
|
|
825
826
|
const tSSE = performance.now();
|
|
@@ -827,6 +828,7 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
827
828
|
const list = productList || [];
|
|
828
829
|
(0, import_product.perfMark)("loadProductsByServer.SSE", performance.now() - tSSE, { count: list.length });
|
|
829
830
|
this.logInfo("通过 DataSource SSE 加载商品列表成功", {
|
|
831
|
+
trigger,
|
|
830
832
|
productCount: list.length,
|
|
831
833
|
duration: `${Math.round(performance.now() - t0)}ms`
|
|
832
834
|
});
|
|
@@ -840,6 +842,7 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
840
842
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
841
843
|
console.error("[Products] 加载商品数据失败:", error);
|
|
842
844
|
this.logError("通过 DataSource SSE 加载商品列表失败", {
|
|
845
|
+
trigger,
|
|
843
846
|
duration: `${duration}ms`,
|
|
844
847
|
error: errorMessage
|
|
845
848
|
});
|
|
@@ -1030,7 +1033,9 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
1030
1033
|
async refreshProducts() {
|
|
1031
1034
|
const tTotal = performance.now();
|
|
1032
1035
|
this.logInfo("refreshProducts 开始");
|
|
1033
|
-
const products = await this.loadProductsByServer(
|
|
1036
|
+
const products = await this.loadProductsByServer({
|
|
1037
|
+
trigger: "product_sync"
|
|
1038
|
+
});
|
|
1034
1039
|
if (products && products.length > 0) {
|
|
1035
1040
|
this.store.list = products;
|
|
1036
1041
|
this.syncProductsMap();
|
|
@@ -1075,18 +1080,23 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
1075
1080
|
this.logWarning("loadProductsFromIndexDB: dbManager 不可用");
|
|
1076
1081
|
return [];
|
|
1077
1082
|
}
|
|
1083
|
+
const startedAt = performance.now();
|
|
1078
1084
|
try {
|
|
1079
|
-
const t0 = performance.now();
|
|
1080
1085
|
const products = await this.dbManager.getAll(INDEXDB_STORE_NAME);
|
|
1081
|
-
|
|
1086
|
+
const durationMs = +(performance.now() - startedAt).toFixed(2);
|
|
1087
|
+
(0, import_product.perfMark)("loadProductsFromIndexDB", durationMs, { count: (products == null ? void 0 : products.length) ?? 0 });
|
|
1082
1088
|
this.logInfo("从 IndexDB 加载商品数据", {
|
|
1083
|
-
productCount: (products == null ? void 0 : products.length) ?? 0
|
|
1089
|
+
productCount: (products == null ? void 0 : products.length) ?? 0,
|
|
1090
|
+
durationMs
|
|
1084
1091
|
});
|
|
1085
1092
|
return products || [];
|
|
1086
1093
|
} catch (error) {
|
|
1087
1094
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1088
1095
|
console.error("[Products] 从 IndexDB 读取数据失败:", error);
|
|
1089
|
-
this.logError("从 IndexDB 读取数据失败", {
|
|
1096
|
+
this.logError("从 IndexDB 读取数据失败", {
|
|
1097
|
+
durationMs: +(performance.now() - startedAt).toFixed(2),
|
|
1098
|
+
error: errorMessage
|
|
1099
|
+
});
|
|
1090
1100
|
return [];
|
|
1091
1101
|
}
|
|
1092
1102
|
}
|
|
@@ -1114,22 +1124,54 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
1114
1124
|
this.logWarning("replaceProductsSnapshotInIndexDB: dbManager 不可用");
|
|
1115
1125
|
return;
|
|
1116
1126
|
}
|
|
1127
|
+
const enqueuedAt = performance.now();
|
|
1128
|
+
let queueWaitMs = 0;
|
|
1129
|
+
let clearDurationMs = 0;
|
|
1130
|
+
let writeDurationMs = 0;
|
|
1117
1131
|
try {
|
|
1118
1132
|
await this.runInProductIndexDBSaveQueue(async () => {
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1133
|
+
const operationStartedAt = performance.now();
|
|
1134
|
+
queueWaitMs = +(operationStartedAt - enqueuedAt).toFixed(2);
|
|
1135
|
+
this.logInfo("replaceProductsSnapshotInIndexDB 开始", {
|
|
1136
|
+
source,
|
|
1137
|
+
productCount: products.length,
|
|
1138
|
+
queueWaitMs
|
|
1139
|
+
});
|
|
1140
|
+
const clearStartedAt = performance.now();
|
|
1141
|
+
try {
|
|
1142
|
+
await this.dbManager.clear(INDEXDB_STORE_NAME);
|
|
1143
|
+
} finally {
|
|
1144
|
+
clearDurationMs = +(performance.now() - clearStartedAt).toFixed(2);
|
|
1145
|
+
}
|
|
1122
1146
|
if (products.length > 0) {
|
|
1123
|
-
|
|
1147
|
+
const writeStartedAt = performance.now();
|
|
1148
|
+
try {
|
|
1149
|
+
await this.dbManager.bulkUpdate(INDEXDB_STORE_NAME, products);
|
|
1150
|
+
} finally {
|
|
1151
|
+
writeDurationMs = +(performance.now() - writeStartedAt).toFixed(2);
|
|
1152
|
+
}
|
|
1124
1153
|
}
|
|
1125
|
-
|
|
1126
|
-
|
|
1154
|
+
const executeDurationMs = +(performance.now() - operationStartedAt).toFixed(2);
|
|
1155
|
+
(0, import_product.perfMark)("replaceProductsSnapshotInIndexDB", executeDurationMs, { count: products.length });
|
|
1156
|
+
this.logInfo("replaceProductsSnapshotInIndexDB 完成", {
|
|
1157
|
+
source,
|
|
1158
|
+
productCount: products.length,
|
|
1159
|
+
queueWaitMs,
|
|
1160
|
+
clearDurationMs,
|
|
1161
|
+
writeDurationMs,
|
|
1162
|
+
executeDurationMs,
|
|
1163
|
+
totalDurationMs: +(performance.now() - enqueuedAt).toFixed(2)
|
|
1164
|
+
});
|
|
1127
1165
|
});
|
|
1128
1166
|
} catch (error) {
|
|
1129
1167
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1130
1168
|
this.logError("全量保存商品到 IndexDB 失败", {
|
|
1131
1169
|
source,
|
|
1132
1170
|
productCount: products.length,
|
|
1171
|
+
queueWaitMs,
|
|
1172
|
+
clearDurationMs,
|
|
1173
|
+
writeDurationMs,
|
|
1174
|
+
totalDurationMs: +(performance.now() - enqueuedAt).toFixed(2),
|
|
1133
1175
|
error: errorMessage
|
|
1134
1176
|
});
|
|
1135
1177
|
}
|
|
@@ -1211,6 +1253,7 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
1211
1253
|
source: "IndexDB"
|
|
1212
1254
|
});
|
|
1213
1255
|
this.logInfo("预加载完成(从 IndexDB)", {
|
|
1256
|
+
trigger: "preload",
|
|
1214
1257
|
productCount: cachedData.length,
|
|
1215
1258
|
duration: `${Math.round(performance.now() - tTotal)}ms`,
|
|
1216
1259
|
source: "IndexDB"
|
|
@@ -1226,7 +1269,9 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
1226
1269
|
this.logWarning("从 IndexDB 加载数据失败,准备从服务器加载", { error: errorMessage });
|
|
1227
1270
|
}
|
|
1228
1271
|
const tServer = performance.now();
|
|
1229
|
-
const products = await this.loadProductsByServer(
|
|
1272
|
+
const products = await this.loadProductsByServer({
|
|
1273
|
+
trigger: "preload"
|
|
1274
|
+
});
|
|
1230
1275
|
(0, import_product.perfMark)("preload.loadFromServer", performance.now() - tServer, { count: (products == null ? void 0 : products.length) ?? 0 });
|
|
1231
1276
|
if (products && products.length > 0) {
|
|
1232
1277
|
this.store.list = products;
|
|
@@ -1239,6 +1284,7 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
1239
1284
|
source: "Server"
|
|
1240
1285
|
});
|
|
1241
1286
|
this.logInfo("预加载完成(从服务器)", {
|
|
1287
|
+
trigger: "preload",
|
|
1242
1288
|
productCount: products.length,
|
|
1243
1289
|
duration: `${Math.round(performance.now() - tTotal)}ms`,
|
|
1244
1290
|
source: "Server"
|
|
@@ -1603,17 +1649,31 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
1603
1649
|
* 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
|
|
1604
1650
|
* @returns 刷新后的商品列表
|
|
1605
1651
|
*/
|
|
1606
|
-
async silentRefresh() {
|
|
1652
|
+
async silentRefresh(options = {}) {
|
|
1607
1653
|
const t0 = performance.now();
|
|
1608
1654
|
const now = Date.now();
|
|
1609
|
-
const
|
|
1610
|
-
const
|
|
1611
|
-
|
|
1655
|
+
const trigger = options.trigger || "background";
|
|
1656
|
+
const elapsedSincePreloadMs = now - this.lastPreloadCompletedAtMs;
|
|
1657
|
+
const elapsedSinceFullFetchMs = now - this.lastServerFullFetchAtMs;
|
|
1658
|
+
if (this.lastPreloadCompletedAtMs > 0 && elapsedSincePreloadMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS || this.lastServerFullFetchAtMs > 0 && elapsedSinceFullFetchMs < PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS) {
|
|
1659
|
+
this.logInfo("silentRefresh 跳过全量 SSE", {
|
|
1660
|
+
trigger,
|
|
1661
|
+
reason: "within_min_interval",
|
|
1662
|
+
minIntervalMs: PRODUCT_SILENT_REFRESH_MIN_INTERVAL_MS,
|
|
1663
|
+
elapsedSincePreloadMs,
|
|
1664
|
+
elapsedSinceFullFetchMs,
|
|
1665
|
+
productCount: this.store.list.length
|
|
1666
|
+
});
|
|
1612
1667
|
return this.store.list;
|
|
1613
1668
|
}
|
|
1614
|
-
this.logInfo("silentRefresh 开始"
|
|
1669
|
+
this.logInfo("silentRefresh 开始", {
|
|
1670
|
+
trigger,
|
|
1671
|
+
elapsedSincePreloadMs,
|
|
1672
|
+
elapsedSinceFullFetchMs,
|
|
1673
|
+
productCount: this.store.list.length
|
|
1674
|
+
});
|
|
1615
1675
|
try {
|
|
1616
|
-
const products = await this.loadProductsByServer();
|
|
1676
|
+
const products = await this.loadProductsByServer({ trigger });
|
|
1617
1677
|
if (products && products.length > 0) {
|
|
1618
1678
|
this.store.list = products;
|
|
1619
1679
|
this.syncProductsMap();
|
|
@@ -1621,6 +1681,7 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
1621
1681
|
this.core.effects.emit(import_types.ProductsHooks.onProductsChanged, this.store.list);
|
|
1622
1682
|
await this.core.effects.emit(import_types.ProductsHooks.onProductsSyncCompleted, null);
|
|
1623
1683
|
this.logInfo("silentRefresh 完成", {
|
|
1684
|
+
trigger,
|
|
1624
1685
|
productCount: products.length,
|
|
1625
1686
|
duration: `${Math.round(performance.now() - t0)}ms`
|
|
1626
1687
|
});
|
|
@@ -1632,6 +1693,7 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
|
|
|
1632
1693
|
} catch (error) {
|
|
1633
1694
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1634
1695
|
this.logError("silentRefresh 失败", {
|
|
1696
|
+
trigger,
|
|
1635
1697
|
duration: `${Math.round(performance.now() - t0)}ms`,
|
|
1636
1698
|
error: errorMessage
|
|
1637
1699
|
});
|