Skip to content

Commit d6d577b

Browse files
committed
fix: some more mod view lifecycle things
1 parent 5f122b7 commit d6d577b

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

views/moderation.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ module.exports = function (cabal, authDb, infoDb) {
195195
// view lifecycle
196196
storeState: function (state, cb) {
197197
state = state.toString('base64')
198-
db.put('state', state, cb)
198+
authDb.put('state', state, cb)
199199
},
200200

201201
fetchState: function (cb) {
202-
db.get('state', function (err, state) {
202+
authDb.get('state', function (err, state) {
203203
if (err && err.notFound) cb()
204204
else if (err) cb(err)
205205
else cb(null, Buffer.from(state, 'base64'))
@@ -209,22 +209,39 @@ module.exports = function (cabal, authDb, infoDb) {
209209
clearIndex: function (cb) {
210210
var batch = []
211211
var maxSize = 5000
212-
db.open(function () {
213-
pump(db.createKeyStream(), new Writable({
212+
let pending = 2
213+
infoDb.open(function () {
214+
pump(infoDb.createKeyStream(), new Writable({
214215
objectMode: true,
215216
write: function (key, enc, next) {
216217
batch.push({ type: 'del', key })
217218
if (batch.length >= maxSize) {
218-
db.batch(batch, next)
219+
infoDb.batch(batch, next)
219220
} else next()
220221
},
221222
final: function (next) {
222-
if (batch.length > 0) db.batch(batch, next)
223+
if (batch.length > 0) infoDb.batch(batch, next)
224+
else next()
225+
}
226+
}), ondone)
227+
})
228+
authDb.open(function () {
229+
pump(authDb.createKeyStream(), new Writable({
230+
objectMode: true,
231+
write: function (key, enc, next) {
232+
batch.push({ type: 'del', key })
233+
if (batch.length >= maxSize) {
234+
authDb.batch(batch, next)
235+
} else next()
236+
},
237+
final: function (next) {
238+
if (batch.length > 0) authDb.batch(batch, next)
223239
else next()
224240
}
225241
}), ondone)
226242
})
227243
function ondone (err) {
244+
if (--pending) return
228245
if (err) cb(err)
229246
else cb()
230247
}

0 commit comments

Comments
 (0)