| 203 | return cb.promise; |
| 204 | |
| 205 | function prepareAndDoRectify(rev) { |
| 206 | // avoid setting rev and prev to the same value |
| 207 | if (currentRev === rev) { |
| 208 | change.debug('rev and prev are equal (not updating anything)'); |
| 209 | return cb(null, change); |
| 210 | } |
| 211 | |
| 212 | // FIXME(@bajtos) Allow callers to pass in the checkpoint value |
| 213 | // (or even better - a memoized async function to get the cp value) |
| 214 | // That will enable `rectifyAll` to cache the checkpoint value |
| 215 | change.constructor.getCheckpointModel().current( |
| 216 | function(err, checkpoint) { |
| 217 | if (err) return cb(err); |
| 218 | doRectify(checkpoint, rev); |
| 219 | }, |
| 220 | ); |
| 221 | } |
| 222 | |
| 223 | function doRectify(checkpoint, rev) { |
| 224 | if (rev) { |