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