Skip to content

Commit

Permalink
fix: add lifecycle management to mod view
Browse files Browse the repository at this point in the history
  • Loading branch information
hackergrrl committed May 22, 2020
1 parent 0214803 commit 70c86c4
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions views/moderation.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,44 @@ module.exports = function (cabal, authDb, infoDb) {
removeFlags: function (core, opts, cb) {
publishFlagUpdate(core, 'remove', opts, cb)
},
},

// view lifecycle
storeState: function (state, cb) {
state = state.toString('base64')
db.put('state', state, cb)
},

fetchState: function (cb) {
db.get('state', function (err, state) {
if (err && err.notFound) cb()
else if (err) cb(err)
else cb(null, Buffer.from(state, 'base64'))
})
},

clearIndex: function (cb) {
var batch = []
var maxSize = 5000
pump(dataDb.createKeyStream(), new Writable({
objectMode: true,
write: function (key, enc, next) {
batch.push({ type: 'del', key })
if (batch.length >= maxSize) {
console.log('deleting', batch.length, 'entries')
dataDb.batch(batch, next)
} else next()
},
final: function (next) {
if (batch.length > 0) dataDb.batch(batch, next)
else next()
}
}), ondone)
function ondone (err) {
console.log('done')
if (err) cb(err)
else cb()
}
}
}

Expand Down

0 comments on commit 70c86c4

Please sign in to comment.