mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #10715 from overleaf/jpa-web-share-mongo-pool
[web] share mongo connection pool between Mongoose and native db GitOrigin-RevId: 8bb2a9dc76880144a8681cb564183906df624cc0
This commit is contained in:
parent
4b856dbd70
commit
f8a1da1b47
3 changed files with 9 additions and 21 deletions
|
@ -2,7 +2,6 @@ const mongoose = require('mongoose')
|
|||
const Settings = require('@overleaf/settings')
|
||||
const logger = require('@overleaf/logger')
|
||||
const { addConnectionDrainer } = require('./GracefulShutdown')
|
||||
const { collectStatsForDb } = require('./mongodb')
|
||||
|
||||
if (
|
||||
typeof global.beforeEach === 'function' &&
|
||||
|
@ -61,8 +60,6 @@ async function getNativeDb() {
|
|||
return mongooseInstance.connection.db
|
||||
}
|
||||
|
||||
getNativeDb().then(db => collectStatsForDb(db, 'mongoose'))
|
||||
|
||||
mongoose.getNativeDb = getNativeDb
|
||||
mongoose.connectionPromise = connectionPromise
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
const Metrics = require('@overleaf/metrics')
|
||||
const Settings = require('@overleaf/settings')
|
||||
const { MongoClient, ObjectId } = require('mongodb')
|
||||
const { ObjectId } = require('mongodb')
|
||||
const OError = require('@overleaf/o-error')
|
||||
const {
|
||||
addConnectionDrainer,
|
||||
addOptionalCleanupHandlerAfterDrainingConnections,
|
||||
} = require('./GracefulShutdown')
|
||||
const { getNativeDb } = require('./Mongoose')
|
||||
|
||||
if (
|
||||
typeof global.beforeEach === 'function' &&
|
||||
|
@ -16,15 +15,6 @@ if (
|
|||
)
|
||||
}
|
||||
|
||||
const clientPromise = MongoClient.connect(
|
||||
Settings.mongo.url,
|
||||
Settings.mongo.options
|
||||
)
|
||||
addConnectionDrainer('mongodb', async () => {
|
||||
const client = await clientPromise
|
||||
client.close()
|
||||
})
|
||||
|
||||
let setupDbPromise
|
||||
async function waitForDb() {
|
||||
if (!setupDbPromise) {
|
||||
|
@ -35,8 +25,8 @@ async function waitForDb() {
|
|||
|
||||
const db = {}
|
||||
async function setupDb() {
|
||||
const internalDb = (await clientPromise).db()
|
||||
collectStatsForDb(internalDb, 'native')
|
||||
const internalDb = await getNativeDb()
|
||||
collectStatsForDb(internalDb, 'shared')
|
||||
|
||||
db.contacts = internalDb.collection('contacts')
|
||||
db.deletedFiles = internalDb.collection('deletedFiles')
|
||||
|
@ -92,14 +82,14 @@ async function setupDb() {
|
|||
}
|
||||
|
||||
async function getCollectionNames() {
|
||||
const internalDb = (await clientPromise).db()
|
||||
const internalDb = await getNativeDb()
|
||||
|
||||
const collections = await internalDb.collections()
|
||||
return collections.map(collection => collection.collectionName)
|
||||
}
|
||||
|
||||
async function dropTestDatabase() {
|
||||
const internalDb = (await clientPromise).db()
|
||||
const internalDb = await getNativeDb()
|
||||
const dbName = internalDb.databaseName
|
||||
const env = process.env.NODE_ENV
|
||||
|
||||
|
@ -116,7 +106,7 @@ async function dropTestDatabase() {
|
|||
* WARNING: Consider using a pre-populated collection from `db` to avoid typos!
|
||||
*/
|
||||
async function getCollectionInternal(name) {
|
||||
const internalDb = (await clientPromise).db()
|
||||
const internalDb = await getNativeDb()
|
||||
return internalDb.collection(name)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@ function filterOutput(line) {
|
|||
return (
|
||||
!line.startsWith('Using settings from ') &&
|
||||
!line.startsWith('Using default settings from ') &&
|
||||
!line.startsWith('CoffeeScript settings file')
|
||||
!line.startsWith('CoffeeScript settings file') &&
|
||||
!line.includes('mongoose default connection open')
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue