diff --git a/src/utils/actions.ts b/src/utils/actions.ts index fd6a535..2e83b12 100755 --- a/src/utils/actions.ts +++ b/src/utils/actions.ts @@ -500,32 +500,36 @@ export function loadJSON( dataFiles: Array, dataDir: string ): Array { - const res: Array = dataFiles.reduce((acc, dataFile, index) => { - const dataPath = dataDir + dataFile.path + const res: Array = dataFiles.reduce( + (acc: QuestionDb[], dataFile, index) => { + const dataPath = dataDir + dataFile.path - if (!utils.FileExists(dataPath)) { - logger.Log( - `${dataPath} data file does not exist, created empty one!`, - 'yellowbg' - ) - utils.WriteFile(JSON.stringify([]), dataPath) - } + if (!utils.FileExists(dataPath)) { + logger.Log( + `${dataPath} data file does not exist, created empty one!`, + 'yellowbg' + ) + utils.WriteFile(JSON.stringify([]), dataPath) + } - try { - acc.push({ - ...dataFile, - index: index, - data: loadData(dataPath), - }) - } catch (err) { - console.error(err) - logger.Log( - "data is undefined! Couldn't load data!", - logger.GetColor('redbg') - ) - } - return acc - }, []) + try { + acc.push({ + ...dataFile, + path: dataPath, + index: index, + data: loadData(dataPath), + }) + } catch (err) { + console.error(err) + logger.Log( + "data is undefined! Couldn't load data!", + logger.GetColor('redbg') + ) + } + return acc + }, + [] + ) const { subjCount, questionCount } = countOfQdbs(res) logger.Log( diff --git a/src/utils/ids.ts b/src/utils/ids.ts index c1483c4..0bf52d3 100755 --- a/src/utils/ids.ts +++ b/src/utils/ids.ts @@ -28,7 +28,8 @@ import logger from '../utils/logger' import { paths } from './files' -const writeInterval = 1 +// TODO: on process exit write all +const writeInterval = 20 let idStatsData = {} let idvStatsData = {} diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 24945f8..d0fdbfd 100755 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -31,6 +31,7 @@ import { paths } from './files' const colors = ['green', 'red', 'yellow', 'blue', 'magenta', 'cyan'] const logFileName = 'log' +// TODO: on process exit write all const writeInterval = 10 const debugLevel = parseInt(process.env.NS_LOGLEVEL) || 0 diff --git a/src/worker/handlers/handleQuestionsToPeers.ts b/src/worker/handlers/handleQuestionsToPeers.ts index c4e9242..af0c06d 100644 --- a/src/worker/handlers/handleQuestionsToPeers.ts +++ b/src/worker/handlers/handleQuestionsToPeers.ts @@ -115,7 +115,6 @@ export const handleQuestionsToPeers = async ( if (res.error || !res.data?.success) { results.errors.push(peer) - console.error('AAAAAAAAAAAAAAAAAAAAAAA') console.error(res.error || JSON.stringify(res.data)) } else if (res.data?.totalNewQuestions > 0) { results.hasNew.push(peer)