mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-01 23:37:43 +03:00
Optimised emitChange
for destroyed resources
no issue - see comment in code base
This commit is contained in:
parent
fb79f24316
commit
aecca28257
@ -101,7 +101,15 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
||||
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) {
|
||||
const previousAttributes = model._previousAttributes;
|
||||
|
||||
if (!options.transacting) {
|
||||
return common.events.emit(event, model, options);
|
||||
}
|
||||
@ -119,8 +127,11 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
||||
}
|
||||
|
||||
_.each(this.ghostEvents, (ghostEvent) => {
|
||||
model._previousAttributes = previousAttributes;
|
||||
common.events.emit(ghostEvent, model, _.omit(options, 'transacting'));
|
||||
});
|
||||
|
||||
delete model.ghostEvents;
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user