mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Threads store their own qdb. It gets updated when new questions are added to reduce message sizes between threads
This commit is contained in:
parent
906ab8ee62
commit
68dcbff846
5 changed files with 56 additions and 141 deletions
|
@ -35,11 +35,16 @@ import {
|
|||
backupData,
|
||||
loadJSON,
|
||||
RecievedData,
|
||||
getQuestionDbsWithoutFunct,
|
||||
} from '../../utils/actions'
|
||||
import dbtools from '../../utils/dbtools'
|
||||
import auth from '../../middlewares/auth.middleware'
|
||||
import { dataToString } from '../../utils/classes'
|
||||
import { initWorkerPool, doALongTask } from '../../utils/workerPool'
|
||||
import {
|
||||
initWorkerPool,
|
||||
doALongTask,
|
||||
msgAllWorker,
|
||||
} from '../../utils/workerPool'
|
||||
|
||||
import { SetupData } from '../../server'
|
||||
import { ModuleType, User, DataFile, Request } from '../../types/basicTypes'
|
||||
|
@ -76,8 +81,6 @@ let publicdirs = []
|
|||
function GetApp(): ModuleType {
|
||||
const app = express()
|
||||
|
||||
initWorkerPool()
|
||||
|
||||
const publicDir = publicdirs[0]
|
||||
if (!publicDir) {
|
||||
throw new Error(`No public dir! ( API )`)
|
||||
|
@ -166,6 +169,8 @@ function GetApp(): ModuleType {
|
|||
// FIXME: check type from file
|
||||
let testUsers: any = []
|
||||
|
||||
initWorkerPool(getQuestionDbsWithoutFunct(questionDbs))
|
||||
|
||||
function mergeObjSum(a, b) {
|
||||
const res = { ...b }
|
||||
Object.keys(a).forEach((key) => {
|
||||
|
@ -1031,6 +1036,10 @@ function GetApp(): ModuleType {
|
|||
success: resultArray.length > 0,
|
||||
newQuestions: resultArray,
|
||||
})
|
||||
msgAllWorker({
|
||||
qdbs: getQuestionDbsWithoutFunct(questionDbs),
|
||||
type: 'update',
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.Log(
|
||||
|
@ -1067,18 +1076,7 @@ function GetApp(): ModuleType {
|
|||
if (req.query.q && req.query.data) {
|
||||
const subj: any = req.query.subj || ''
|
||||
const question = req.query.q
|
||||
let recData: any = req.query.data
|
||||
if (typeof recData === 'string') {
|
||||
try {
|
||||
recData = JSON.parse(recData)
|
||||
} catch (err) {
|
||||
logger.Log(
|
||||
'Error parsing recData in /ask!',
|
||||
logger.GetColor('redbg')
|
||||
)
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
const recData: any = req.query.data
|
||||
|
||||
const promises = []
|
||||
|
||||
|
@ -1087,8 +1085,8 @@ function GetApp(): ModuleType {
|
|||
doALongTask({
|
||||
type: 'work',
|
||||
data: {
|
||||
qdb: qdb.data,
|
||||
question,
|
||||
searchIn: [qdb.index], // TODO: search in all
|
||||
question: question,
|
||||
subjName: subj,
|
||||
questionData: recData,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue