Skip to content

Commit

Permalink
fix: mod view clearing race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
hackergrrl committed May 22, 2020
1 parent 5c7cb7a commit d997041
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions views/moderation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var mauth = require('materialized-group-auth')
var Writable = require('readable-stream').Writable
var sub = require('subleveldown')
var EventEmitter = require('events').EventEmitter
var { Readable, Transform } = require('readable-stream')
Expand Down Expand Up @@ -150,13 +151,13 @@ module.exports = function (cabal, authDb, infoDb) {
cb = opts
opts = {}
}
var r = auth.list(opts)
var out = through.obj(function (row, enc, next) {
row.channel = row.group
delete row.group
next(null, row)
})
this.ready(function () {
var r = auth.list(opts)
pump(r, out)
})
var ro = readonly(out)
Expand Down Expand Up @@ -208,22 +209,22 @@ module.exports = function (cabal, authDb, infoDb) {
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)
db.open(function () {
pump(db.createKeyStream(), new Writable({
objectMode: true,
write: function (key, enc, next) {
batch.push({ type: 'del', key })
if (batch.length >= maxSize) {
db.batch(batch, next)
} else next()
},
final: function (next) {
if (batch.length > 0) db.batch(batch, next)
else next()
}
}), ondone)
})
function ondone (err) {
console.log('done')
if (err) cb(err)
else cb()
}
Expand Down

0 comments on commit d997041

Please sign in to comment.