Update update.js

This commit is contained in:
Aleksandr Statciuk 2022-09-08 21:09:43 +03:00
parent 081d4174a8
commit 814936d14d
1 changed files with 4 additions and 13 deletions

View File

@ -19,9 +19,7 @@ main()
async function updateStreams(items = [], results = {}, origins = {}) {
logger.info('updating streams...')
let buffer = {}
let updated = 0
let removed = 0
const now = dayjs.utc().format()
for (const item of items) {
const stream = store.create(item)
@ -46,23 +44,16 @@ async function updateStreams(items = [], results = {}, origins = {}) {
}
}
if (buffer[stream.get('url')]) {
await db.streams.remove({ _id: stream.get('_id') })
removed++
} else {
buffer[stream.get('url')] = true
if (stream.changed) {
stream.set('updated_at', { updated_at: now })
await db.streams.update({ _id: stream.get('_id') }, stream.data())
updated++
}
}
}
db.streams.compact()
logger.info(`updated ${updated} streams`)
logger.info(`removed ${removed} duplicates`)
logger.info('done')
}