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