mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Answering questions using worker poolz
This commit is contained in:
parent
f5f3b51eee
commit
d8695682f7
4 changed files with 67 additions and 91 deletions
|
@ -38,7 +38,8 @@ import {
|
|||
} from '../../utils/actions'
|
||||
import dbtools from '../../utils/dbtools'
|
||||
import auth from '../../middlewares/auth.middleware'
|
||||
import { dataToString, searchDatas } from '../../utils/classes'
|
||||
import { dataToString } from '../../utils/classes'
|
||||
import { initWorkerPool, doALongTask } from '../../utils/workerPool'
|
||||
|
||||
import { SetupData } from '../../server'
|
||||
import { ModuleType, User, DataFile, Request } from '../../types/basicTypes'
|
||||
|
@ -75,6 +76,8 @@ let publicdirs = []
|
|||
function GetApp(): ModuleType {
|
||||
const app = express()
|
||||
|
||||
initWorkerPool()
|
||||
|
||||
const publicDir = publicdirs[0]
|
||||
if (!publicDir) {
|
||||
throw new Error(`No public dir! ( API )`)
|
||||
|
@ -1066,7 +1069,19 @@ function GetApp(): ModuleType {
|
|||
const question = req.query.q
|
||||
const recData: any = req.query.data
|
||||
|
||||
searchDatas(questionDbs, question, subj, recData)
|
||||
const promises = []
|
||||
|
||||
questionDbs.map((qdb, i) => {
|
||||
promises.push(
|
||||
doALongTask(i, {
|
||||
type: 'work',
|
||||
index: i,
|
||||
data: { qdb: qdb.data, question, subjName: subj, recData },
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
Promise.all(promises)
|
||||
.then((result) => {
|
||||
try {
|
||||
const mergedResult = result.reduce((acc, dbRes) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue