mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
Added condition to not trigger events if nothing has changed
refs #9248 - we no longer trigger events if the db was not changed
This commit is contained in:
parent
3289dc7619
commit
8b3336c84d
@ -117,7 +117,12 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
||||
*/
|
||||
emitChange: function (model, event, options) {
|
||||
if (!options.transacting) {
|
||||
if (model._changed && !Object.keys(model._changed).length) {
|
||||
return;
|
||||
}
|
||||
|
||||
debug(`event trigger without txn: ${event}`);
|
||||
|
||||
return common.events.emit(event, model, options);
|
||||
}
|
||||
|
||||
@ -137,6 +142,10 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
||||
}
|
||||
|
||||
_.each(this.ghostEvents, (ghostEvent) => {
|
||||
if (model._changed && !Object.keys(model._changed).length) {
|
||||
return;
|
||||
}
|
||||
|
||||
debug(`event: ${ghostEvent}`);
|
||||
common.events.emit(ghostEvent, model, _.omit(options, 'transacting'));
|
||||
});
|
||||
|
@ -449,7 +449,7 @@ describe('Post Model', function () {
|
||||
});
|
||||
}).then(function () {
|
||||
// txn was successful
|
||||
Object.keys(eventsTriggered).length.should.eql(6);
|
||||
Object.keys(eventsTriggered).length.should.eql(4);
|
||||
});
|
||||
});
|
||||
|
||||
@ -708,8 +708,8 @@ describe('Post Model', function () {
|
||||
should.exist(edited);
|
||||
edited.attributes.status.should.equal('scheduled');
|
||||
|
||||
Object.keys(eventsTriggered).length.should.eql(1);
|
||||
should.exist(eventsTriggered['post.edited']);
|
||||
// nothing has changed
|
||||
Object.keys(eventsTriggered).length.should.eql(0);
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
|
Loading…
Reference in New Issue
Block a user