qdb data path fix

This commit is contained in:
mrfry 2023-04-26 22:04:34 +02:00
parent 773e7eda0b
commit c295781b48
4 changed files with 31 additions and 26 deletions

View file

@ -500,32 +500,36 @@ export function loadJSON(
dataFiles: Array<DataFile>, dataFiles: Array<DataFile>,
dataDir: string dataDir: string
): Array<QuestionDb> { ): Array<QuestionDb> {
const res: Array<QuestionDb> = dataFiles.reduce((acc, dataFile, index) => { const res: Array<QuestionDb> = dataFiles.reduce(
const dataPath = dataDir + dataFile.path (acc: QuestionDb[], dataFile, index) => {
const dataPath = dataDir + dataFile.path
if (!utils.FileExists(dataPath)) { if (!utils.FileExists(dataPath)) {
logger.Log( logger.Log(
`${dataPath} data file does not exist, created empty one!`, `${dataPath} data file does not exist, created empty one!`,
'yellowbg' 'yellowbg'
) )
utils.WriteFile(JSON.stringify([]), dataPath) utils.WriteFile(JSON.stringify([]), dataPath)
} }
try { try {
acc.push({ acc.push({
...dataFile, ...dataFile,
index: index, path: dataPath,
data: loadData(dataPath), index: index,
}) data: loadData(dataPath),
} catch (err) { })
console.error(err) } catch (err) {
logger.Log( console.error(err)
"data is undefined! Couldn't load data!", logger.Log(
logger.GetColor('redbg') "data is undefined! Couldn't load data!",
) logger.GetColor('redbg')
} )
return acc }
}, []) return acc
},
[]
)
const { subjCount, questionCount } = countOfQdbs(res) const { subjCount, questionCount } = countOfQdbs(res)
logger.Log( logger.Log(

View file

@ -28,7 +28,8 @@ import logger from '../utils/logger'
import { paths } from './files' import { paths } from './files'
const writeInterval = 1 // TODO: on process exit write all
const writeInterval = 20
let idStatsData = {} let idStatsData = {}
let idvStatsData = {} let idvStatsData = {}

View file

@ -31,6 +31,7 @@ import { paths } from './files'
const colors = ['green', 'red', 'yellow', 'blue', 'magenta', 'cyan'] const colors = ['green', 'red', 'yellow', 'blue', 'magenta', 'cyan']
const logFileName = 'log' const logFileName = 'log'
// TODO: on process exit write all
const writeInterval = 10 const writeInterval = 10
const debugLevel = parseInt(process.env.NS_LOGLEVEL) || 0 const debugLevel = parseInt(process.env.NS_LOGLEVEL) || 0

View file

@ -115,7 +115,6 @@ export const handleQuestionsToPeers = async (
if (res.error || !res.data?.success) { if (res.error || !res.data?.success) {
results.errors.push(peer) results.errors.push(peer)
console.error('AAAAAAAAAAAAAAAAAAAAAAA')
console.error(res.error || JSON.stringify(res.data)) console.error(res.error || JSON.stringify(res.data))
} else if (res.data?.totalNewQuestions > 0) { } else if (res.data?.totalNewQuestions > 0) {
results.hasNew.push(peer) results.hasNew.push(peer)