mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
Merge pull request #10939 from overleaf/em-upgrade-mongo-notifications
Upgrade Mongo driver in notifications GitOrigin-RevId: 3a504471b21873e614e617d81c15c3e17ce7fdc0
This commit is contained in:
@@ -14,7 +14,7 @@ const express = require('express')
|
||||
const app = express()
|
||||
const methodOverride = require('method-override')
|
||||
const bodyParser = require('body-parser')
|
||||
const mongodb = require('./app/js/mongodb')
|
||||
const { mongoClient } = require('./app/js/mongodb')
|
||||
const controller = require('./app/js/NotificationsController')
|
||||
|
||||
metrics.memory.monitor(logger)
|
||||
@@ -64,8 +64,8 @@ const port =
|
||||
x1 => x1.port
|
||||
) || 3042
|
||||
|
||||
mongodb
|
||||
.waitForDb()
|
||||
mongoClient
|
||||
.connect()
|
||||
.then(() => {
|
||||
app.listen(port, host, () =>
|
||||
logger.debug(`notifications starting up, listening on ${host}:${port}`)
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
const { db, ObjectId } = require('./mongodb')
|
||||
const request = require('request')
|
||||
const async = require('async')
|
||||
const _ = require('underscore')
|
||||
const settings = require('@overleaf/settings')
|
||||
const { port } = settings.internal.notifications
|
||||
const logger = require('@overleaf/logger')
|
||||
@@ -56,8 +55,7 @@ module.exports = {
|
||||
logger.err({ err }, e)
|
||||
return cb(e)
|
||||
}
|
||||
const hasNotification = _.some(
|
||||
body,
|
||||
const hasNotification = body.some(
|
||||
notification =>
|
||||
notification.key === notification_key &&
|
||||
notification.user_id === user_id.toString()
|
||||
|
||||
@@ -1,28 +1,15 @@
|
||||
const Settings = require('@overleaf/settings')
|
||||
const { MongoClient, ObjectId } = require('mongodb')
|
||||
|
||||
const clientPromise = MongoClient.connect(
|
||||
Settings.mongo.url,
|
||||
Settings.mongo.options
|
||||
)
|
||||
const mongoClient = new MongoClient(Settings.mongo.url)
|
||||
const mongoDb = mongoClient.db()
|
||||
|
||||
let setupDbPromise
|
||||
async function waitForDb() {
|
||||
if (!setupDbPromise) {
|
||||
setupDbPromise = setupDb()
|
||||
}
|
||||
await setupDbPromise
|
||||
}
|
||||
|
||||
const db = {}
|
||||
async function setupDb() {
|
||||
const internalDb = (await clientPromise).db()
|
||||
|
||||
db.notifications = internalDb.collection('notifications')
|
||||
const db = {
|
||||
notifications: mongoDb.collection('notifications'),
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
db,
|
||||
mongoClient,
|
||||
ObjectId,
|
||||
waitForDb,
|
||||
}
|
||||
|
||||
@@ -7,10 +7,6 @@ module.exports = {
|
||||
},
|
||||
|
||||
mongo: {
|
||||
options: {
|
||||
useUnifiedTopology:
|
||||
(process.env.MONGO_USE_UNIFIED_TOPOLOGY || 'true') === 'true',
|
||||
},
|
||||
url:
|
||||
process.env.MONGO_CONNECTION_STRING ||
|
||||
`mongodb://${process.env.MONGO_HOST || 'localhost'}/sharelatex`,
|
||||
|
||||
@@ -26,9 +26,8 @@
|
||||
"bunyan": "^1.8.15",
|
||||
"express": "4.17.1",
|
||||
"method-override": "^3.0.0",
|
||||
"mongodb": "^3.6.0",
|
||||
"request": "^2.88.2",
|
||||
"underscore": "1.13.1"
|
||||
"mongodb": "^4.11.0",
|
||||
"request": "^2.88.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^4.3.6",
|
||||
|
||||
Reference in New Issue
Block a user