Skip to content

Commit

Permalink
feat(edit-logs): do not save empty edit logs (empty = really empty or…
Browse files Browse the repository at this point in the history
… with just latestChangeBy modified)
  • Loading branch information
naholyr committed Sep 6, 2017
1 parent 509b003 commit 414954a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions server/lib/edit-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,17 @@ const middleware = schema => {
}
else {
// If the model was updated, we only store a diff
const changes = deepDiff(cleanupData(this._original), cleanupData(data))
editLog.diff = flattenDiff(changes)
const changes = flattenDiff(deepDiff(cleanupData(this._original), cleanupData(data)))
if (changes.length === 0) {
// No change at all: do not save any edit log
return next()
}
if (changes.length === 1 && changes[0].path.length === 1 && changes[0].path[0] === 'latestChangeBy') {
// No actual change, the only modified field is 'latestChangeBy', which is pretty meaningless
// Do not save any edit log
return next()
}
editLog.diff = changes
}

this._elLogToBeSaved = new EditLog(editLog)
Expand Down

0 comments on commit 414954a

Please sign in to comment.