| 1585 | // all compaction is done in a queue, to avoid attaching |
| 1586 | // too many listeners at once |
| 1587 | function doNextCompaction(self) { |
| 1588 | var task = self._compactionQueue[0]; |
| 1589 | var opts = task.opts; |
| 1590 | var callback = task.callback; |
| 1591 | self.get('_local/compaction').catch(function () { |
| 1592 | return false; |
| 1593 | }).then(function (doc) { |
| 1594 | if (doc && doc.last_seq) { |
| 1595 | opts.last_seq = doc.last_seq; |
| 1596 | } |
| 1597 | self._compact(opts, function (err, res$$1) { |
| 1598 | /* istanbul ignore if */ |
| 1599 | if (err) { |
| 1600 | callback(err); |
| 1601 | } else { |
| 1602 | callback(null, res$$1); |
| 1603 | } |
| 1604 | nextTick(function () { |
| 1605 | self._compactionQueue.shift(); |
| 1606 | if (self._compactionQueue.length) { |
| 1607 | doNextCompaction(self); |
| 1608 | } |
| 1609 | }); |
| 1610 | }); |
| 1611 | }); |
| 1612 | } |
| 1613 | |
| 1614 | function appendPurgeSeq(db, docId, rev$$1) { |
| 1615 | return db.get('_local/purges').then(function (doc) { |