mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Optimised emitChange
for destroyed resources
no issue - see comment in code base
This commit is contained in:
parent
fb79f24316
commit
aecca28257
1 changed files with 11 additions and 0 deletions
|
@ -101,7 +101,15 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @NOTE
|
||||||
|
* We have to remember the `_previousAttributes` attributes, because when destroying resources
|
||||||
|
* We listen on the `onDestroyed` event and Bookshelf resets these properties right after the event.
|
||||||
|
* If the query runs in a txn, `_previousAttributes` will be empty.
|
||||||
|
*/
|
||||||
emitChange: function (model, event, options) {
|
emitChange: function (model, event, options) {
|
||||||
|
const previousAttributes = model._previousAttributes;
|
||||||
|
|
||||||
if (!options.transacting) {
|
if (!options.transacting) {
|
||||||
return common.events.emit(event, model, options);
|
return common.events.emit(event, model, options);
|
||||||
}
|
}
|
||||||
|
@ -119,8 +127,11 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
_.each(this.ghostEvents, (ghostEvent) => {
|
_.each(this.ghostEvents, (ghostEvent) => {
|
||||||
|
model._previousAttributes = previousAttributes;
|
||||||
common.events.emit(ghostEvent, model, _.omit(options, 'transacting'));
|
common.events.emit(ghostEvent, model, _.omit(options, 'transacting'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
delete model.ghostEvents;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue