mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
perf: ⚡ Salva solo le relations che sono state modificate
This commit is contained in:
@ -417,12 +417,20 @@ export class RecordsPage extends Page {
|
|||||||
await this.setFields(model, relations, data);
|
await this.setFields(model, relations, data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Save relations
|
// Save relations (only those that changed)
|
||||||
for (const [relation, relatedModel] of Object.entries(relations)) {
|
const relationsToSave = data.filter((value: any, key: string) => key.includes(':'))
|
||||||
const response = await relatedModel.save();
|
.keys()
|
||||||
if (response.getModelId()) {
|
.map((item) => item.split(':')[0])
|
||||||
model.setRelation(relation, response.getModel());
|
.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)) {
|
||||||
|
model.setRelation(relation, relatedModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await model.save();
|
const response = await model.save();
|
||||||
|
Reference in New Issue
Block a user