mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
rm duplicates promise fix, process logging improvements
This commit is contained in:
parent
967755969e
commit
9ddff88ebd
1 changed files with 16 additions and 12 deletions
|
@ -71,22 +71,20 @@ if (stat.isDirectory()) {
|
||||||
|
|
||||||
if (!dbB) {
|
if (!dbB) {
|
||||||
log(`Removing duplicate questions from ${C('green')}${pathA}${C()}`)
|
log(`Removing duplicate questions from ${C('green')}${pathA}${C()}`)
|
||||||
rmDuplicates(dbA).then((res) => {
|
const res = rmDuplicates(dbA)
|
||||||
console.timeEnd('rmduplicates')
|
console.timeEnd('rmduplicates')
|
||||||
writeData(res, resultDbFileName)
|
writeData(res, resultDbFileName)
|
||||||
log('File written')
|
log('File written')
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
log(
|
log(
|
||||||
`Removing questions found in ${C('green')}${pathB}${C()} from ${C(
|
`Removing questions found in ${C('green')}${pathB}${C()} from ${C(
|
||||||
'green'
|
'green'
|
||||||
)}${pathA}${C()}`
|
)}${pathA}${C()}`
|
||||||
)
|
)
|
||||||
difference({ dbA: dbA, dbB: dbB }).then((res) => {
|
const res = difference({ dbA: dbA, dbB: dbB })
|
||||||
console.timeEnd('rmduplicates')
|
console.timeEnd('rmduplicates')
|
||||||
writeData(res, resultDbFileName)
|
writeData(res, resultDbFileName)
|
||||||
log('File written')
|
log('File written')
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,6 +237,7 @@ function difference({ dbA, dbB }) {
|
||||||
const resultDb = []
|
const resultDb = []
|
||||||
let dbLength = 0
|
let dbLength = 0
|
||||||
let removedTotal = 0
|
let removedTotal = 0
|
||||||
|
let processedQuestions = 0
|
||||||
|
|
||||||
iterateSubjects(dbA, () => {
|
iterateSubjects(dbA, () => {
|
||||||
dbLength++
|
dbLength++
|
||||||
|
@ -265,6 +264,7 @@ function difference({ dbA, dbB }) {
|
||||||
)}${subj.Questions.length}${C('green')} questions${C()}`
|
)}${subj.Questions.length}${C('green')} questions${C()}`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
printProgressBar(i + 1, dbA.length)
|
||||||
for (let j = 0; j < subj.Questions.length; j++) {
|
for (let j = 0; j < subj.Questions.length; j++) {
|
||||||
const question = subj.Questions[j]
|
const question = subj.Questions[j]
|
||||||
const searchRes = search({
|
const searchRes = search({
|
||||||
|
@ -275,7 +275,8 @@ function difference({ dbA, dbB }) {
|
||||||
searchTillMatchPercent: minpercent,
|
searchTillMatchPercent: minpercent,
|
||||||
})
|
})
|
||||||
|
|
||||||
printProgressBar(j + 1, subj.Questions.length)
|
printProgressBar(processedQuestions, dbLength)
|
||||||
|
processedQuestions++
|
||||||
|
|
||||||
const res = hasRequiredPercent(searchRes, minpercent)
|
const res = hasRequiredPercent(searchRes, minpercent)
|
||||||
|
|
||||||
|
@ -380,6 +381,9 @@ function hr() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(text) {
|
function log(text) {
|
||||||
|
process.stdout.clearLine()
|
||||||
|
process.stdout.cursorTo(0)
|
||||||
|
|
||||||
console.log(text)
|
console.log(text)
|
||||||
utils.AppendToFile(text, globalLog)
|
utils.AppendToFile(text, globalLog)
|
||||||
}
|
}
|
||||||
|
@ -395,7 +399,7 @@ function writeInSameLine(text, returnToLineStart) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function printProgressBar(current, total) {
|
function printProgressBar(current, total) {
|
||||||
const width = process.stdout.columns - 25
|
const width = process.stdout.columns - 30
|
||||||
|
|
||||||
if (width <= 0) {
|
if (width <= 0) {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue