Update cleanup-database.js
This commit is contained in:
parent
712650e65c
commit
b016b84160
|
@ -1,11 +1,21 @@
|
|||
const { db, logger } = require('../core')
|
||||
|
||||
async function main() {
|
||||
const removed = await db.remove(
|
||||
{ 'status.code': { $in: ['timeout', 'offline'] } },
|
||||
{ multi: true }
|
||||
)
|
||||
logger.info(`Loading database...`)
|
||||
let streams = await db.find({})
|
||||
|
||||
logger.info(`Removing broken links...`)
|
||||
let removed = 0
|
||||
const buffer = []
|
||||
for (const stream of streams) {
|
||||
const duplicate = buffer.find(i => i.id === stream.id)
|
||||
if (duplicate && ['offline', 'timeout'].includes(stream.status.code)) {
|
||||
await db.remove({ _id: stream._id })
|
||||
removed++
|
||||
} else {
|
||||
buffer.push(stream)
|
||||
}
|
||||
}
|
||||
db.compact()
|
||||
|
||||
logger.info(`Removed ${removed} links`)
|
||||
|
|
Loading…
Reference in New Issue