diff --git a/libs/database/init.js b/libs/database/init.js index 34ccd8c..c52cdf5 100644 --- a/libs/database/init.js +++ b/libs/database/init.js @@ -5,10 +5,7 @@ import { open } from 'sqlite' const log = initLog("database") -export let sqlite = await open({ - filename: 'ddnet.sqlite', - driver: sqlite3.cached.Database -}) +export let sqlite = undefined /** * This initializes both the sqlite db and mongodb. @@ -30,7 +27,9 @@ async function init() { useNewUrlParser: true, useUnifiedTopology: true } - ).then(() => log("Connected to mongodb!")) + ) + + log("Connected to mongodb!") } export default init \ No newline at end of file diff --git a/libs/utils/multithread.js b/libs/utils/multithread.js index 1d1de6c..4c94336 100644 --- a/libs/utils/multithread.js +++ b/libs/utils/multithread.js @@ -1,5 +1,5 @@ import { randomUUID } from 'crypto' -import { Worker } from 'worker_threads' +import { SHARE_ENV, Worker } from 'worker_threads' import initLog from './log.js' const log = initLog("Worker Setup") @@ -26,7 +26,7 @@ function waitForThread() { export function initWorkers(threads) { for (let i = 0; i < threads; ++i) { - workerFarm.push(new Worker('./libs/utils/multithread/genericWorker.js')) + workerFarm.push(new Worker('./libs/utils/multithread/genericWorker.js', { env: SHARE_ENV })) } for (const i in workerFarm) { diff --git a/libs/utils/multithread/mongoForWorkes.js b/libs/utils/multithread/mongoForWorkes.js new file mode 100644 index 0000000..f81162d --- /dev/null +++ b/libs/utils/multithread/mongoForWorkes.js @@ -0,0 +1,11 @@ +import mongoose from 'mongoose' + +export async function connectMongoose() { + await mongoose.connect( + process.env.MONGO_URI, + { + useNewUrlParser: true, + useUnifiedTopology: true + } + ) +} \ No newline at end of file diff --git a/libs/utils/multithread/playerMonthPoints.js b/libs/utils/multithread/playerMonthPoints.js index a6b3aea..f45ae71 100644 --- a/libs/utils/multithread/playerMonthPoints.js +++ b/libs/utils/multithread/playerMonthPoints.js @@ -1,9 +1,7 @@ import Player from '../../../schemas/Player.js' -import init from '../../database/init.js' -import { config } from 'dotenv' +import { connectMongoose } from './mongoForWorkes.js' -config() -init() +connectMongoose() export function main(data) { return new Promise( diff --git a/libs/utils/multithread/playerPoints.js b/libs/utils/multithread/playerPoints.js index b4fc138..b13c86b 100644 --- a/libs/utils/multithread/playerPoints.js +++ b/libs/utils/multithread/playerPoints.js @@ -1,9 +1,7 @@ import Player from '../../../schemas/Player.js' -import init from '../../database/init.js' -import { config } from 'dotenv' +import { connectMongoose } from './mongoForWorkes.js' -config() -init() +connectMongoose() export function main(data) { return new Promise( diff --git a/libs/utils/multithread/playerRankPoints.js b/libs/utils/multithread/playerRankPoints.js index 55ba4a3..35df9c6 100644 --- a/libs/utils/multithread/playerRankPoints.js +++ b/libs/utils/multithread/playerRankPoints.js @@ -1,9 +1,7 @@ import Player from '../../../schemas/Player.js' -import init from '../../database/init.js' -import { config } from 'dotenv' +import { connectMongoose } from './mongoForWorkes.js' -config() -init() +connectMongoose() export function main(data) { return new Promise( diff --git a/libs/utils/multithread/playerTeamPoints.js b/libs/utils/multithread/playerTeamPoints.js index 7d52c4e..7c36831 100644 --- a/libs/utils/multithread/playerTeamPoints.js +++ b/libs/utils/multithread/playerTeamPoints.js @@ -1,9 +1,7 @@ import Player from '../../../schemas/Player.js' -import init from '../../database/init.js' -import { config } from 'dotenv' +import { connectMongoose } from './mongoForWorkes.js' -config() -init() +connectMongoose() export function main(data) { return new Promise( diff --git a/libs/utils/multithread/playerWeekPoints.js b/libs/utils/multithread/playerWeekPoints.js index f1a38be..d8b3186 100644 --- a/libs/utils/multithread/playerWeekPoints.js +++ b/libs/utils/multithread/playerWeekPoints.js @@ -1,9 +1,7 @@ import Player from '../../../schemas/Player.js' -import init from '../../database/init.js' -import { config } from 'dotenv' +import { connectMongoose } from './mongoForWorkes.js' -config() -init() +connectMongoose() export function main(data) { return new Promise(