iptv/scripts/commands/database/cleanup.js
Aleksandr Statciuk b39dc83f8b Update .gitignore
2022-02-13 01:38:07 +03:00

26 lines
620 B
JavaScript

const { db, logger } = require('../../core')
async function main() {
logger.info(`loading streams...`)
await db.streams.load()
let streams = await db.streams.find({})
logger.info(`removing broken links...`)
let removed = 0
const buffer = {}
for (const stream of streams) {
const duplicate = buffer[stream.channel_id]
if (duplicate && ['offline', 'timeout'].includes(stream.status.code)) {
await db.streams.remove({ _id: stream._id })
removed++
} else {
buffer[stream.channel_id] = stream
}
}
db.streams.compact()
logger.info(`removed ${removed} links`)
}
main()