Skip to content

Commit

Permalink
fix: add clearIndex lifecycle to channel-membership
Browse files Browse the repository at this point in the history
  • Loading branch information
hackergrrl committed May 30, 2020
1 parent 3a32497 commit 3b6eaeb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
26 changes: 24 additions & 2 deletions views/channel-membership.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var EventEmitter = require('events').EventEmitter
const EventEmitter = require('events').EventEmitter
const pump = require('pump')
const Writable = require('readable-stream').Writable

/*
view data structure, the value (1) doesn't matter
Expand All @@ -14,7 +16,7 @@ module.exports = function (lvl) {
var events = new EventEmitter()

return {
maxBatch: 100,
maxBatch: 500,
map: function (msgs, next) {
// 1. go over each msg
// 2. check if it's a leave/join msg (skip if not)
Expand Down Expand Up @@ -123,6 +125,26 @@ module.exports = function (lvl) {
else cb(null, Buffer.from(state, 'base64'))
})
},

clearIndex: function (cb) {
var batch = []
var maxSize = 5000
lvl.open(function () {
pump(lvl.createKeyStream(), new Writable({
objectMode: true,
write: function (key, enc, next) {
batch.push({ type: 'del', key })
if (batch.length >= maxSize) {
lvl.batch(batch, next)
} else next()
},
final: function (next) {
if (batch.length > 0) lvl.batch(batch, next)
else next()
}
}), cb)
})
}
}
}

Expand Down
1 change: 1 addition & 0 deletions views/moderation.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ module.exports = function (cabal, authDb, infoDb) {
})

return {
maxBatch: 500,
map: wrap(map),
api: {
events: events,
Expand Down

0 comments on commit 3b6eaeb

Please sign in to comment.