mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Workers can now search in multiple specified db-s
This commit is contained in:
parent
68dcbff846
commit
19b8fdc5ab
5 changed files with 57 additions and 52 deletions
|
@ -495,33 +495,48 @@ if (!isMainThread) {
|
|||
|
||||
parentPort.on('message', (msg) => {
|
||||
if (msg.type === 'work') {
|
||||
const { searchIn, subjName, question, questionData } = msg.data
|
||||
const { subjName, question, questionData } = msg.data
|
||||
const index = msg.index
|
||||
const searchIn = msg.data.searchIn
|
||||
|
||||
console.log(
|
||||
`[THREAD #${workerIndex}]: staring work${
|
||||
!isNaN(index) ? ` on job index #${index}` : ''
|
||||
}`
|
||||
)
|
||||
|
||||
let searchResult = null
|
||||
const currQdb = qdbs.find((qdb) => {
|
||||
return searchIn[0] === qdb.index
|
||||
})
|
||||
let searchResult = []
|
||||
|
||||
try {
|
||||
searchResult = doSearch(currQdb.data, subjName, question, questionData)
|
||||
qdbs.forEach((qdb) => {
|
||||
if (searchIn === 'all' || searchIn.includes(qdb.index)) {
|
||||
const res = doSearch(qdb.data, subjName, question, questionData)
|
||||
searchResult = [...searchResult, ...res]
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
logger.Log('Error in worker thread!', logger.GetColor('redbg'))
|
||||
console.error(err)
|
||||
}
|
||||
|
||||
// sorting
|
||||
const sortedResult = searchResult.sort((q1, q2) => {
|
||||
if (q1.match < q2.match) {
|
||||
return 1
|
||||
} else if (q1.match > q2.match) {
|
||||
return -1
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
})
|
||||
|
||||
// ONDONE:
|
||||
parentPort.postMessage({
|
||||
msg: `From thread #${workerIndex}: job ${
|
||||
!isNaN(index) ? `#${index}` : ''
|
||||
}done`,
|
||||
workerIndex: workerIndex,
|
||||
result: searchResult,
|
||||
result: sortedResult,
|
||||
})
|
||||
|
||||
console.log(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue