mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-17 07:01:03 +00: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 Settings = require('@overleaf/settings')
|
||||||
const logger = require('@overleaf/logger')
|
const logger = require('@overleaf/logger')
|
||||||
const { addConnectionDrainer } = require('./GracefulShutdown')
|
const { addConnectionDrainer } = require('./GracefulShutdown')
|
||||||
const { collectStatsForDb } = require('./mongodb')
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof global.beforeEach === 'function' &&
|
typeof global.beforeEach === 'function' &&
|
||||||
|
@ -61,8 +60,6 @@ async function getNativeDb() {
|
||||||
return mongooseInstance.connection.db
|
return mongooseInstance.connection.db
|
||||||
}
|
}
|
||||||
|
|
||||||
getNativeDb().then(db => collectStatsForDb(db, 'mongoose'))
|
|
||||||
|
|
||||||
mongoose.getNativeDb = getNativeDb
|
mongoose.getNativeDb = getNativeDb
|
||||||
mongoose.connectionPromise = connectionPromise
|
mongoose.connectionPromise = connectionPromise
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
const Metrics = require('@overleaf/metrics')
|
const Metrics = require('@overleaf/metrics')
|
||||||
const Settings = require('@overleaf/settings')
|
const { ObjectId } = require('mongodb')
|
||||||
const { MongoClient, ObjectId } = require('mongodb')
|
|
||||||
const OError = require('@overleaf/o-error')
|
const OError = require('@overleaf/o-error')
|
||||||
const {
|
const {
|
||||||
addConnectionDrainer,
|
|
||||||
addOptionalCleanupHandlerAfterDrainingConnections,
|
addOptionalCleanupHandlerAfterDrainingConnections,
|
||||||
} = require('./GracefulShutdown')
|
} = require('./GracefulShutdown')
|
||||||
|
const { getNativeDb } = require('./Mongoose')
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof global.beforeEach === 'function' &&
|
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
|
let setupDbPromise
|
||||||
async function waitForDb() {
|
async function waitForDb() {
|
||||||
if (!setupDbPromise) {
|
if (!setupDbPromise) {
|
||||||
|
@ -35,8 +25,8 @@ async function waitForDb() {
|
||||||
|
|
||||||
const db = {}
|
const db = {}
|
||||||
async function setupDb() {
|
async function setupDb() {
|
||||||
const internalDb = (await clientPromise).db()
|
const internalDb = await getNativeDb()
|
||||||
collectStatsForDb(internalDb, 'native')
|
collectStatsForDb(internalDb, 'shared')
|
||||||
|
|
||||||
db.contacts = internalDb.collection('contacts')
|
db.contacts = internalDb.collection('contacts')
|
||||||
db.deletedFiles = internalDb.collection('deletedFiles')
|
db.deletedFiles = internalDb.collection('deletedFiles')
|
||||||
|
@ -92,14 +82,14 @@ async function setupDb() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCollectionNames() {
|
async function getCollectionNames() {
|
||||||
const internalDb = (await clientPromise).db()
|
const internalDb = await getNativeDb()
|
||||||
|
|
||||||
const collections = await internalDb.collections()
|
const collections = await internalDb.collections()
|
||||||
return collections.map(collection => collection.collectionName)
|
return collections.map(collection => collection.collectionName)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function dropTestDatabase() {
|
async function dropTestDatabase() {
|
||||||
const internalDb = (await clientPromise).db()
|
const internalDb = await getNativeDb()
|
||||||
const dbName = internalDb.databaseName
|
const dbName = internalDb.databaseName
|
||||||
const env = process.env.NODE_ENV
|
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!
|
* WARNING: Consider using a pre-populated collection from `db` to avoid typos!
|
||||||
*/
|
*/
|
||||||
async function getCollectionInternal(name) {
|
async function getCollectionInternal(name) {
|
||||||
const internalDb = (await clientPromise).db()
|
const internalDb = await getNativeDb()
|
||||||
return internalDb.collection(name)
|
return internalDb.collection(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@ function filterOutput(line) {
|
||||||
return (
|
return (
|
||||||
!line.startsWith('Using settings from ') &&
|
!line.startsWith('Using settings from ') &&
|
||||||
!line.startsWith('Using default 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