@pisell/core 1.0.56 → 1.0.58

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.
@@ -90,13 +90,13 @@ export var setCache = /*#__PURE__*/function () {
90
90
  break;
91
91
  }
92
92
  _context.next = 19;
93
- return app.dbManager.add('requests', cacheData);
93
+ return app.dbManager.debouncedAdd('requests', cacheData);
94
94
  case 19:
95
95
  _context.next = 23;
96
96
  break;
97
97
  case 21:
98
98
  _context.next = 23;
99
- return app.dbManager.update('requests', cacheData);
99
+ return app.dbManager.debouncedUpdate('requests', cacheData);
100
100
  case 23:
101
101
  console.log('设置缓存成功', CACHES);
102
102
  case 24:
@@ -1,4 +1,5 @@
1
1
  import App from "../app";
2
+ export declare const mockPromise: (data: any, timeout?: number) => Promise<unknown>;
2
3
  /**
3
4
  * IndexDB 管理器模块
4
5
  *
@@ -29,11 +29,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/indexDB/index.ts
30
30
  var indexDB_exports = {};
31
31
  __export(indexDB_exports, {
32
- default: () => indexDB_default
32
+ default: () => indexDB_default,
33
+ mockPromise: () => mockPromise
33
34
  });
34
35
  module.exports = __toCommonJS(indexDB_exports);
35
36
  var import_dayjs = __toESM(require("dayjs"));
36
37
  var import_dexie = __toESM(require("dexie"));
38
+ var mockPromise = (data, timeout = 200) => {
39
+ return new Promise((resolve, reject) => {
40
+ setTimeout(() => {
41
+ resolve(data);
42
+ }, timeout);
43
+ });
44
+ };
37
45
  var IndexDBManager = class _IndexDBManager {
38
46
  /**
39
47
  * 检查环境是否支持 IndexedDB
@@ -205,13 +213,6 @@ var IndexDBManager = class _IndexDBManager {
205
213
  * @param data 数据
206
214
  */
207
215
  debouncedAdd(storeName, data) {
208
- if (!this.useIndexDB) {
209
- const storeConfig = this.stores.find((s) => s.name === storeName);
210
- const keyPath = (storeConfig == null ? void 0 : storeConfig.keyPath) || "id";
211
- const key = data[keyPath];
212
- this.getMemoryStore(storeName).set(key, data);
213
- return;
214
- }
215
216
  if (!this.db) return;
216
217
  if (!this.debouncedBuffers.has(storeName)) {
217
218
  this.debouncedBuffers.set(storeName, []);
@@ -240,11 +241,13 @@ var IndexDBManager = class _IndexDBManager {
240
241
  try {
241
242
  while (buffer.length > 0) {
242
243
  const batch = buffer.splice(0, this.debouncedBatchSize);
243
- await this.db.transaction("rw", this.db.table(storeName), async () => {
244
- for (const item of batch) {
244
+ for (const item of batch) {
245
+ await mockPromise({}, this.debouncedDelay);
246
+ try {
245
247
  await this.add(storeName, item);
248
+ } catch (err) {
246
249
  }
247
- });
250
+ }
248
251
  }
249
252
  } catch (error) {
250
253
  this.app.logger.addLog({
@@ -314,11 +317,10 @@ var IndexDBManager = class _IndexDBManager {
314
317
  bufferMap.clear();
315
318
  for (let i = 0; i < entries.length; i += this.debouncedUpdateBatchSize) {
316
319
  const batch = entries.slice(i, i + this.debouncedUpdateBatchSize);
317
- await this.db.transaction("rw", this.db.table(storeName), async () => {
318
- for (const item of batch) {
319
- await this.update(storeName, item);
320
- }
321
- });
320
+ for (const item of batch) {
321
+ await mockPromise(item, this.debouncedUpdateDelay);
322
+ await this.update(storeName, item);
323
+ }
322
324
  }
323
325
  } catch (error) {
324
326
  this.app.logger.addLog({
@@ -756,3 +758,7 @@ var IndexDBManager = class _IndexDBManager {
756
758
  }
757
759
  };
758
760
  var indexDB_default = IndexDBManager;
761
+ // Annotate the CommonJS export names for ESM import in node:
762
+ 0 && (module.exports = {
763
+ mockPromise
764
+ });
@@ -65,9 +65,9 @@ var setCache = async (key, data, cache) => {
65
65
  if (app.dbManager) {
66
66
  let tasksData = await app.dbManager.get("requests", key);
67
67
  if (!tasksData) {
68
- await app.dbManager.add("requests", cacheData);
68
+ await app.dbManager.debouncedAdd("requests", cacheData);
69
69
  } else {
70
- await app.dbManager.update("requests", cacheData);
70
+ await app.dbManager.debouncedUpdate("requests", cacheData);
71
71
  }
72
72
  }
73
73
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/core",
3
- "version": "1.0.56",
3
+ "version": "1.0.58",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",