dtable-statistic 5.0.48-alpha.16 → 5.0.48-alpha.17

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/es/index.js CHANGED
@@ -76,6 +76,7 @@ class Statistic {
76
76
  if (!window.app) return;
77
77
  _resultCacheManager.viewRowsCacheManager.clear();
78
78
  _resultCacheManager.formulaResultsCacheManager.clear();
79
+ (0, _resultCacheManager.clearCachedBase)();
79
80
  window.app.unmountWidget({
80
81
  animation
81
82
  });
@@ -21,6 +21,9 @@ async function calcViewRowsWithWorker(view, table, value, username, userId, user
21
21
  if (cachedRows) {
22
22
  return cachedRows;
23
23
  }
24
+ if (!_resultCacheManager.cachedBase) {
25
+ (0, _resultCacheManager.initCachedBase)(value);
26
+ }
24
27
  const clonedTable = (0, _lodashEs.cloneDeep)(table);
25
28
  // Symbol can't passed to workers
26
29
  clonedTable.columns = clonedTable.columns.map(c => {
@@ -36,7 +39,7 @@ async function calcViewRowsWithWorker(view, table, value, username, userId, user
36
39
  return [];
37
40
  }
38
41
  const calcWorker = Comlink.wrap(worker);
39
- const rows = await calcWorker.getViewRows(view, clonedTable, value, username, userId, userDepartmentIdsMap);
42
+ const rows = await calcWorker.getViewRows(view, clonedTable, _resultCacheManager.cachedBase, username, userId, userDepartmentIdsMap);
40
43
  _resultCacheManager.viewRowsCacheManager.set(key, rows);
41
44
  _threadManager.default.removeThread(workerId);
42
45
  return rows;
@@ -47,6 +50,9 @@ async function calcFormulaResultsWithWorker(table, rows, value, formulaColumns,
47
50
  if (cachedResults) {
48
51
  return cachedResults;
49
52
  }
53
+ if (!_resultCacheManager.cachedBase) {
54
+ (0, _resultCacheManager.initCachedBase)(value);
55
+ }
50
56
  const clonedTable = (0, _lodashEs.cloneDeep)(table);
51
57
  // Symbol can't passed to workers
52
58
  clonedTable.columns = clonedTable.columns.map(c => {
@@ -62,7 +68,7 @@ async function calcFormulaResultsWithWorker(table, rows, value, formulaColumns,
62
68
  return [];
63
69
  }
64
70
  const calcWorker = Comlink.wrap(worker);
65
- const results = await calcWorker.getTableFormulaResults(clonedTable, rows, value, formulaColumns, username, userId, userDepartmentIdsMap);
71
+ const results = await calcWorker.getTableFormulaResults(clonedTable, rows, _resultCacheManager.cachedBase, formulaColumns, username, userId, userDepartmentIdsMap);
66
72
  _resultCacheManager.formulaResultsCacheManager.set(key, results);
67
73
  _threadManager.default.removeThread(workerId);
68
74
  return results;
@@ -3,7 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.viewRowsCacheManager = exports.formulaResultsCacheManager = void 0;
6
+ exports.cachedBase = void 0;
7
+ exports.clearCachedBase = clearCachedBase;
8
+ exports.formulaResultsCacheManager = void 0;
9
+ exports.initCachedBase = initCachedBase;
10
+ exports.viewRowsCacheManager = void 0;
11
+ var _lodashEs = require("lodash-es");
7
12
  class ResultCacheManager {
8
13
  constructor() {
9
14
  this.cache = new Map();
@@ -19,4 +24,30 @@ class ResultCacheManager {
19
24
  }
20
25
  }
21
26
  const viewRowsCacheManager = exports.viewRowsCacheManager = new ResultCacheManager();
22
- const formulaResultsCacheManager = exports.formulaResultsCacheManager = new ResultCacheManager();
27
+ const formulaResultsCacheManager = exports.formulaResultsCacheManager = new ResultCacheManager();
28
+ let cachedBase = exports.cachedBase = null;
29
+ function initCachedBase(value) {
30
+ // don't clone rows cause they are really big
31
+ const tableIdRowMap = {};
32
+ value.tables.forEach(t => {
33
+ tableIdRowMap[t._id] = t === null || t === void 0 ? void 0 : t.rows;
34
+ t.rows && delete t.rows;
35
+ });
36
+ const clonedBase = (0, _lodashEs.cloneDeep)(value);
37
+ clonedBase.tables.forEach(t => {
38
+ // delete symbols
39
+ t.columns = t.columns.map(c => {
40
+ delete c.editor;
41
+ delete c.formatter;
42
+ return c;
43
+ });
44
+ t.rows = tableIdRowMap[t._id];
45
+ });
46
+ value.tables.forEach(t => {
47
+ t.rows = tableIdRowMap[t._id];
48
+ });
49
+ exports.cachedBase = cachedBase = clonedBase;
50
+ }
51
+ function clearCachedBase() {
52
+ exports.cachedBase = cachedBase = null;
53
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-statistic",
3
- "version": "5.0.48-alpha.16",
3
+ "version": "5.0.48-alpha.17",
4
4
  "description": "statistics",
5
5
  "main": "dist/dtable-statistic.js",
6
6
  "author": "seafile",