Skip to content

Commit 3ef0e5f

Browse files
committed
data.RecordFactory: performance improvement needed for big data #6247
1 parent 032c032 commit 3ef0e5f

1 file changed

Lines changed: 16 additions & 25 deletions

File tree

src/data/RecordFactory.mjs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,33 @@ class RecordFactory extends Base {
3535

3636
/**
3737
* @param {Object} data
38-
* @param {Object} data.config
3938
* @param {Object} data.field
4039
* @param {Neo.data.RecordFactory} data.me
4140
* @param {Neo.data.Model} data.model
4241
* @param {String} data.path=''
4342
*/
44-
createField({config, field, me, model, path=''}) {
45-
let value = Neo.ns(field.mapping || field.name, false, config),
46-
fieldName = field.name.split('.').pop(),
43+
createField({field, me, model, path=''}) {
44+
let fieldName = field.name.split('.').pop(),
4745
symbol = Symbol.for(fieldName),
48-
fieldPath, parsedValue, properties;
46+
fieldPath, properties,
47+
value;
4948

5049
if (field.fields) {
5150
field.fields.forEach(childField => {
5251
fieldPath = path.split('.');
5352
fieldPath = fieldPath.filter(Boolean);
5453
fieldPath.push(field.name);
5554

56-
this.createField({config, field: childField, me, model, path: fieldPath.join('.')})
55+
this.createField({field: childField, me, model, path: fieldPath.join('.')})
5756
})
5857
} else {
5958
if (value === undefined && Object.hasOwn(field, 'defaultValue')) {
6059
value = field.defaultValue
6160
}
6261

63-
parsedValue = instance.parseRecordValue(me, field, value, config);
64-
6562
properties = {
6663
[symbol]: {
67-
value : Neo.clone(parsedValue, true),
64+
value,
6865
writable: true
6966
},
7067
[fieldName]: {
@@ -78,7 +75,7 @@ class RecordFactory extends Base {
7875

7976
value = instance.parseRecordValue(me, field, value);
8077

81-
if (!Neo.isEqual(value, oldValue)) {
78+
if (!Neo.isEqual(value, oldValue)) {console.log(value, oldValue)
8279
this[symbol] = value;
8380

8481
me._isModified = true;
@@ -97,7 +94,7 @@ class RecordFactory extends Base {
9794
// adding the original value of each field
9895
if (model.trackModifiedFields) {
9996
properties[instance.ovPrefix + field.name] = {
100-
value: parsedValue
97+
value
10198
}
10299
}
103100

@@ -139,20 +136,8 @@ class RecordFactory extends Base {
139136
static name = 'Record'
140137

141138
constructor(config) {
142-
let me = this;
143-
144-
Object.defineProperties(me, {
145-
_isModified: {
146-
value : false,
147-
writable: true
148-
}
149-
});
150-
151-
if (Array.isArray(model.fields)) {
152-
model.fields.forEach(field => {
153-
instance.createField({config, field, me, model})
154-
})
155-
}
139+
this.setSilent(config);
140+
this._isModified = false
156141
}
157142

158143
/**
@@ -172,6 +157,12 @@ class RecordFactory extends Base {
172157
}
173158
};
174159

160+
if (Array.isArray(model.fields)) {
161+
model.fields.forEach(field => {
162+
instance.createField({field, me: cls.prototype, model})
163+
})
164+
}
165+
175166
Object.defineProperty(cls.prototype, 'isRecord', {value: true});
176167
Object.defineProperty(cls, 'isClass', {value: true});
177168

0 commit comments

Comments
 (0)