From 89326c7630f49cfd7bf9f5d817cad670788bfa15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Thu, 17 Sep 2015 18:58:52 +0200 Subject: [PATCH] Fix perf of rectification after updateAttributes Improve the id-detection algorithm in the "after save" hook to correctly handle "updateAttributes" as a single-model change and DO NOT trigger full "rectify all" scan. --- lib/persisted-model.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/persisted-model.js b/lib/persisted-model.js index f823a320..7ff7787a 100644 --- a/lib/persisted-model.js +++ b/lib/persisted-model.js @@ -1419,8 +1419,12 @@ module.exports = function(registry) { }; function rectifyOnSave(ctx, next) { - if (ctx.instance) { - ctx.Model.rectifyChange(ctx.instance.getId(), reportErrorAndNext); + var instance = ctx.instance || ctx.currentInstance; + var id = instance ? instance.getId() : + getIdFromWhereByModelId(ctx.Model, ctx.where); + + if (id) { + ctx.Model.rectifyChange(id, reportErrorAndNext); } else { ctx.Model.rectifyAllChanges(reportErrorAndNext); }