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) {
|
||||
log(`Removing duplicate questions from ${C('green')}${pathA}${C()}`)
|
||||
rmDuplicates(dbA).then((res) => {
|
||||
console.timeEnd('rmduplicates')
|
||||
writeData(res, resultDbFileName)
|
||||
log('File written')
|
||||
})
|
||||
const res = rmDuplicates(dbA)
|
||||
console.timeEnd('rmduplicates')
|
||||
writeData(res, resultDbFileName)
|
||||
log('File written')
|
||||
} else {
|
||||
log(
|
||||
`Removing questions found in ${C('green')}${pathB}${C()} from ${C(
|
||||
'green'
|
||||
)}${pathA}${C()}`
|
||||
)
|
||||
difference({ dbA: dbA, dbB: dbB }).then((res) => {
|
||||
console.timeEnd('rmduplicates')
|
||||
writeData(res, resultDbFileName)
|
||||
log('File written')
|
||||
})
|
||||
const res = difference({ dbA: dbA, dbB: dbB })
|
||||
console.timeEnd('rmduplicates')
|
||||
writeData(res, resultDbFileName)
|
||||
log('File written')
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,6 +237,7 @@ function difference({ dbA, dbB }) {
|
|||
const resultDb = []
|
||||
let dbLength = 0
|
||||
let removedTotal = 0
|
||||
let processedQuestions = 0
|
||||
|
||||
iterateSubjects(dbA, () => {
|
||||
dbLength++
|
||||
|
@ -265,6 +264,7 @@ function difference({ dbA, dbB }) {
|
|||
)}${subj.Questions.length}${C('green')} questions${C()}`
|
||||
)
|
||||
|
||||
printProgressBar(i + 1, dbA.length)
|
||||
for (let j = 0; j < subj.Questions.length; j++) {
|
||||
const question = subj.Questions[j]
|
||||
const searchRes = search({
|
||||
|
@ -275,7 +275,8 @@ function difference({ dbA, dbB }) {
|
|||
searchTillMatchPercent: minpercent,
|
||||
})
|
||||
|
||||
printProgressBar(j + 1, subj.Questions.length)
|
||||
printProgressBar(processedQuestions, dbLength)
|
||||
processedQuestions++
|
||||
|
||||
const res = hasRequiredPercent(searchRes, minpercent)
|
||||
|
||||
|
@ -380,6 +381,9 @@ function hr() {
|
|||
}
|
||||
|
||||
function log(text) {
|
||||
process.stdout.clearLine()
|
||||
process.stdout.cursorTo(0)
|
||||
|
||||
console.log(text)
|
||||
utils.AppendToFile(text, globalLog)
|
||||
}
|
||||
|
@ -395,7 +399,7 @@ function writeInSameLine(text, returnToLineStart) {
|
|||
}
|
||||
|
||||
function printProgressBar(current, total) {
|
||||
const width = process.stdout.columns - 25
|
||||
const width = process.stdout.columns - 30
|
||||
|
||||
if (width <= 0) {
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue