Skip to content

Commit

Permalink
data.RecordFactory: performance improvement needed for big data #6247
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiu committed Jan 16, 2025
1 parent 032c032 commit 3ef0e5f
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions src/data/RecordFactory.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,33 @@ class RecordFactory extends Base {

/**
* @param {Object} data
* @param {Object} data.config
* @param {Object} data.field
* @param {Neo.data.RecordFactory} data.me
* @param {Neo.data.Model} data.model
* @param {String} data.path=''
*/
createField({config, field, me, model, path=''}) {
let value = Neo.ns(field.mapping || field.name, false, config),
fieldName = field.name.split('.').pop(),
createField({field, me, model, path=''}) {
let fieldName = field.name.split('.').pop(),
symbol = Symbol.for(fieldName),
fieldPath, parsedValue, properties;
fieldPath, properties,
value;

if (field.fields) {
field.fields.forEach(childField => {
fieldPath = path.split('.');
fieldPath = fieldPath.filter(Boolean);
fieldPath.push(field.name);

this.createField({config, field: childField, me, model, path: fieldPath.join('.')})
this.createField({field: childField, me, model, path: fieldPath.join('.')})
})
} else {
if (value === undefined && Object.hasOwn(field, 'defaultValue')) {
value = field.defaultValue
}

parsedValue = instance.parseRecordValue(me, field, value, config);

properties = {
[symbol]: {
value : Neo.clone(parsedValue, true),
value,
writable: true
},
[fieldName]: {
Expand All @@ -78,7 +75,7 @@ class RecordFactory extends Base {

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

if (!Neo.isEqual(value, oldValue)) {
if (!Neo.isEqual(value, oldValue)) {console.log(value, oldValue)
this[symbol] = value;

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

Expand Down Expand Up @@ -139,20 +136,8 @@ class RecordFactory extends Base {
static name = 'Record'

constructor(config) {
let me = this;

Object.defineProperties(me, {
_isModified: {
value : false,
writable: true
}
});

if (Array.isArray(model.fields)) {
model.fields.forEach(field => {
instance.createField({config, field, me, model})
})
}
this.setSilent(config);
this._isModified = false
}

/**
Expand All @@ -172,6 +157,12 @@ class RecordFactory extends Base {
}
};

if (Array.isArray(model.fields)) {
model.fields.forEach(field => {
instance.createField({field, me: cls.prototype, model})
})
}

Object.defineProperty(cls.prototype, 'isRecord', {value: true});
Object.defineProperty(cls, 'isClass', {value: true});

Expand Down

0 comments on commit 3ef0e5f

Please sign in to comment.