@nocobase/plugin-field-sort 2.1.0-alpha.46 → 2.1.0-alpha.47

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.
@@ -8,16 +8,16 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/client": "2.1.0-alpha.46",
12
- "@nocobase/client-v2": "2.1.0-alpha.46",
11
+ "@nocobase/client": "2.1.0-alpha.47",
12
+ "@nocobase/client-v2": "2.1.0-alpha.47",
13
13
  "antd": "5.24.2",
14
14
  "react": "18.2.0",
15
- "@nocobase/flow-engine": "2.1.0-alpha.46",
15
+ "@nocobase/flow-engine": "2.1.0-alpha.47",
16
16
  "lodash": "4.18.1",
17
- "@nocobase/database": "2.1.0-alpha.46",
18
- "@nocobase/actions": "2.1.0-alpha.46",
19
- "@nocobase/server": "2.1.0-alpha.46",
20
- "@nocobase/data-source-manager": "2.1.0-alpha.46",
17
+ "@nocobase/database": "2.1.0-alpha.47",
18
+ "@nocobase/actions": "2.1.0-alpha.47",
19
+ "@nocobase/server": "2.1.0-alpha.47",
20
+ "@nocobase/data-source-manager": "2.1.0-alpha.47",
21
21
  "sequelize": "6.35.2",
22
- "@nocobase/lock-manager": "2.1.0-alpha.46"
22
+ "@nocobase/lock-manager": "2.1.0-alpha.47"
23
23
  };
@@ -41,30 +41,37 @@ class SortField extends import_database.Field {
41
41
  const { name, scopeKey } = this.options;
42
42
  const { model } = this.context.collection;
43
43
  instances = Array.isArray(instances) ? instances : [instances];
44
- for (const instance of instances) {
45
- if (from == "create" && (0, import_lodash.isNumber)(instance.get(name))) {
46
- continue;
47
- }
48
- if ((0, import_lodash.isNumber)(instance.get(name)) && instance._previousDataValues[scopeKey] == instance[scopeKey]) {
49
- continue;
50
- }
51
- const where = {};
52
- if (scopeKey) {
53
- const value = instance.get(scopeKey);
54
- if (value !== void 0 && value !== null) {
55
- where[scopeKey] = value;
56
- }
57
- }
58
- await this.constructor.lockManager.runExclusive(
59
- this.context.collection.name,
60
- async () => {
61
- const max = await model.max(name, { ...options, where });
62
- const newValue = (max || 0) + 1;
44
+ await this.constructor.lockManager.runExclusive(
45
+ this.context.collection.name,
46
+ async () => {
47
+ const maxCache = /* @__PURE__ */ new Map();
48
+ for (const instance of instances) {
49
+ if (from == "create" && (0, import_lodash.isNumber)(instance.get(name))) {
50
+ continue;
51
+ }
52
+ if ((0, import_lodash.isNumber)(instance.get(name)) && instance._previousDataValues[scopeKey] == instance[scopeKey]) {
53
+ continue;
54
+ }
55
+ const where = {};
56
+ let cacheKey = "__default__";
57
+ if (scopeKey) {
58
+ const value = instance.get(scopeKey);
59
+ if (value !== void 0 && value !== null) {
60
+ where[scopeKey] = value;
61
+ cacheKey = `${typeof value}:${String(value)}`;
62
+ }
63
+ }
64
+ if (!maxCache.has(cacheKey)) {
65
+ const max = await model.max(name, { ...options, where });
66
+ maxCache.set(cacheKey, max || 0);
67
+ }
68
+ const newValue = (maxCache.get(cacheKey) ?? 0) + 1;
69
+ maxCache.set(cacheKey, newValue);
63
70
  instance.set(name, newValue);
64
- },
65
- 2e3
66
- );
67
- }
71
+ }
72
+ },
73
+ 2e3
74
+ );
68
75
  };
69
76
  onScopeChange = async (instance, options) => {
70
77
  const { scopeKey } = this.options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-field-sort",
3
- "version": "2.1.0-alpha.46",
3
+ "version": "2.1.0-alpha.47",
4
4
  "license": "Apache-2.0",
5
5
  "displayName": "Collection field: Sort",
6
6
  "displayName.ru-RU": "Поле коллекции: Сортировка",
@@ -24,5 +24,5 @@
24
24
  "keywords": [
25
25
  "Collection fields"
26
26
  ],
27
- "gitHead": "42b269944cdd1908d7a848c0af4936fe94c03bb7"
27
+ "gitHead": "66196b57f9043ea0ac6ebdafbc732bfb98af1396"
28
28
  }