perf: Salva solo le relations che sono state modificate

This commit is contained in:
Maicol Battistini 2022-02-08 17:11:31 +01:00
parent 438ae9622c
commit 10094dbe26
No known key found for this signature in database
GPG Key ID: 4FDB0F87CDB1D34A
1 changed files with 13 additions and 5 deletions

View File

@ -417,12 +417,20 @@ export class RecordsPage extends Page {
await this.setFields(model, relations, data);
try {
// Save relations
// Save relations (only those that changed)
const relationsToSave = data.filter((value: any, key: string) => key.includes(':'))
.keys()
.map((item) => item.split(':')[0])
.unique()
.all();
for (const relation of relationsToSave) {
const response = await relations[relation].save();
relations[relation] = response.getModel() as IModel;
}
for (const [relation, relatedModel] of Object.entries(relations)) {
const response = await relatedModel.save();
if (response.getModelId()) {
model.setRelation(relation, response.getModel());
}
model.setRelation(relation, relatedModel);
}
const response = await model.save();