|
@@ -1,11 +1,10 @@
|
|
|
const Metrics = require('@overleaf/metrics')
|
|
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 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()
|
|
|
|
|
- collectStatsForDb(internalDb, 'native')
|
|
|
|
|
|
|
+ const internalDb = await getNativeDb()
|
|
|
|
|
+ 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)
|
|
|
}
|
|
}
|
|
|
|
|
|