mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update create-queue.js
This commit is contained in:
parent
e020e2707f
commit
dfe65a9f3f
1 changed files with 8 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
const { db, file, parser, logger, date, api } = require('../core')
|
const { db, file, parser, logger, date, api } = require('../core')
|
||||||
const { program } = require('commander')
|
const { program } = require('commander')
|
||||||
const { shuffle } = require('lodash')
|
const _ = require('lodash')
|
||||||
|
|
||||||
const options = program
|
const options = program
|
||||||
.option(
|
.option(
|
||||||
|
@ -97,13 +97,18 @@ async function saveToDatabase(items = []) {
|
||||||
logger.info('Saving to the database...')
|
logger.info('Saving to the database...')
|
||||||
await db.queue.load()
|
await db.queue.load()
|
||||||
await db.queue.reset()
|
await db.queue.reset()
|
||||||
const chunks = split(shuffle(items), options.maxClusters)
|
let queue = []
|
||||||
|
const chunks = split(_.shuffle(items), options.maxClusters)
|
||||||
for (const [i, chunk] of chunks.entries()) {
|
for (const [i, chunk] of chunks.entries()) {
|
||||||
for (const item of chunk) {
|
for (const item of chunk) {
|
||||||
item.cluster_id = i + 1
|
item.cluster_id = i + 1
|
||||||
await db.queue.insert(item)
|
queue.push(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
queue = _.sortBy(queue, ['channel.xmltv_id', 'date'])
|
||||||
|
|
||||||
|
await db.queue.insert(queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
function split(arr, n) {
|
function split(arr, n) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue